使用Parse键将链接添加到按钮

时间:2014-04-24 00:04:11

标签: ios xcode parse-platform

所以我试图使用Parse的查询打开一个带按钮的链接。所以查询工作,因为图像和标题确实出现了。关键"链接"自NSLog显示它们以来加载。只是每次加载视图时,列表中的第一个链接都会自动打开。我只是想知道为什么。我希望它在按下按钮时加载它,而不是在加载视图时加载它。如果有任何问题,我会尽力回答它们以澄清问题。先谢谢!

for(self.homeObjectArray中的PFObject * homeObject){

UIView *homeImage = [[UIView alloc] initWithFrame:CGRectMake(0, originY, self.featuredScrollView.frame.size.width, 300)];


//Image
PFFile *image = (PFFile *)[homeObject objectForKey:@"imageFile"];
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]];
userImage.frame = CGRectMake(0, 0, homeImage.frame.size.width, 320);
[homeImage addSubview:userImage];

//Label
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 325, homeImage.frame.size.width, 18)];
headingLabel.text = [homeObject objectForKey:@"Heading"];
headingLabel.textColor = [UIColor redColor];
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.numberOfLines = 2;
[homeImage addSubview:headingLabel];

//Link
NSString *urlString = @"";
urlString = [homeObject objectForKey:@"Link"];
NSLog(@"URLS %@ \n", urlString);
NSURL *url = [[NSURL alloc]initWithString:urlString];
UIButton *linkButton = [UIButton buttonWithType:UIButtonTypeCustom];
linkButton = [[UIButton alloc] initWithFrame:userImage.frame];
[linkButton addTarget:self action:[[UIApplication sharedApplication]openURL:url] forControlEvents:UIControlEventTouchUpInside];
[homeImage addSubview:linkButton];

1 个答案:

答案 0 :(得分:0)

让我们试试:

[linkButton addTarget:self action:@selector(doSomthing) forControlEvents:UIControlEventTouchUpInside];

- (void) doSomthing
{
NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/questions/23257429/adding-links-to-buttons-using-parse-keys"];
[[UIApplication sharedApplication]openURL:url];
}