2012-03-26 106 views
0

我不明白爲什麼代碼不工作,沒有發現我似乎正在工作。所以我來這裏尋求幫助。最終,當我點擊「查看」按鈕時,我希望能夠將鏈接發送到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編程有點新東西。謝謝! :)

回答

1

indexPath.row是一個NSInteger,而不是該位置的文本。這意味着您的NSString *消息正在獲取您所在行的整數值(0,1,2 ...)。從您的網站/ cloudsendList數組中提取時,請嘗試將該位置用作索引。

Ex。

NSString *message = [cloudsendList objectAtIndex:indexPath.row]; 

UPDATE:

要打開瀏覽器,使用相同的概念。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", [cloudsendList objectAtIndex:indexPath.row]]]]; 
+0

怎麼樣「[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:」?我也是這樣做嗎? – chrisjr 2012-03-26 14:22:31

+0

用另一個例子更新。如果您還有其他問題,請告訴我! – Squatch 2012-03-26 14:28:05

+0

非常感謝!對此,我真的非常感激。 :) – chrisjr 2012-03-26 14:30:25