我不明白爲什麼代碼不工作,沒有發現我似乎正在工作。所以我來這裏尋求幫助。最終,當我點擊「查看」按鈕時,我希望能夠將鏈接發送到Safari,並且我希望在點擊「複製」按鈕時複製鏈接。從NSMutableArray tableview單元格抓取文本
下面的代碼(在 「 - (無效)viewDidLoad中 」):
NSMutableArray *sites = [[NSMutableArray alloc] initWithObjects:@"http://www.apple.com/", @"http://www.youtube.com/", @"http://maps.google.com/", @"http://ww.google.com/", @"http://www.stackoverflow.com/", nil];
self.cloudsendList = sites;
下面是代碼(下「 - (IBAction爲)touchUpInsideAction:按鈕(UIButton的*)」):
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
NSUInteger index = [buttons indexOfObject:button];
NSDictionary* buttonInfo = [buttonData objectAtIndex:index];
if ([[buttonInfo objectForKey:@"title"] isEqualToString:@"View"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", indexPath.row]]];
} else if ([[buttonInfo objectForKey:@"title"]isEqualToString:@"Copy"]) {
NSString *message = indexPath.row;
[UIPasteboard generalPasteboard].string = message;
要注意,我能夠看到每個單元格上的NSMutableArray數據,我無法抓住它。我也嘗試插入「cloudsendList indexPath.row」而不是「indexPath.row」,但它不起作用。我希望這給你足夠的信息,任何幫助都會得到真正的讚賞。另外,如果我聽起來有些不好意思,我很抱歉;我仍然對Objective-C編程有點新東西。謝謝! :)
怎麼樣「[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:」?我也是這樣做嗎? – chrisjr 2012-03-26 14:22:31
用另一個例子更新。如果您還有其他問題,請告訴我! – Squatch 2012-03-26 14:28:05
非常感謝!對此,我真的非常感激。 :) – chrisjr 2012-03-26 14:30:25