【发布时间】:2011-01-20 05:29:11
【问题描述】:
我希望你一切都好,我已经在 iphone 上工作了几个星期,目前我遇到了问题,尝试用 url 打开一个 safari,我有一个 json 文件,它带有一个动态的 url。
这里我留下代码。
- (void) loadFiles {
NSArray *_json = [[[self getDataFromJson] objectAtIndex:0] retain];
if ([_json count] > 0)
{
for (int i = 0; i < [_json count]; i++)
{
NSDictionary *file = [_json objectAtIndex:i];
UIImage *buttonImage = [UIImage imageNamed:@"btn.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(openBrowser:) forControlEvents:UIControlEventTouchUpInside];
//works but i have warnings
button.tag = [file objectForKey:@"linkURL"] ;
CGRect frame = CGRectZero;
frame.size = buttonImage.size;
button.frame = frame;
NSString *name = [file objectForKey:@"name"];
NSString *description = [file objectForKey:@"description"];
//Create Box
}
}
}
- (void) openBrowser:(id)sender
{
NSString *url = ((UIControl *) sender).tag;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] ];
}
我需要从 UIButtom 打开一个 URL 没有投诉。 任何建议或帮助谢谢。 干杯
【问题讨论】:
-
标签属性是一个整数,你不能在那里存储一个URL。
标签: iphone objective-c iphone-sdk-3.0 ios4 cocos2d-iphone