2011-05-03 75 views
1

斐伊川,我得到的值從模型類的UITableView具有NsDictionary.Here是我的代碼如何從tableview中NSDictionary的值傳遞給下一個視圖

- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    //UILabel *label = nil;//label to hold description of city 

    static NSString *CellIdentifier = @"Cell"; //cell identifier for each section oftable 

    UITableViewCell *cell = [atableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]autorelease]; //cell 
      } 
// cell.backgroundColor = [UIColor clearColor];//cell background color 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    //label.backgroundColor = [UIColor clearColor]; 

    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:15.0]; 


    cell.textLabel.text = [NSString stringWithFormat:@"%@",[(Tweet *)[recentTweets objectAtIndex:indexPath.row] author]]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",[(Tweet *)[recentTweets objectAtIndex:indexPath.row] tweet]]; 
    cell.detailTextLabel.numberOfLines = 10; 
    cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; 


    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", 
                          [(Tweet *)[recentTweets objectAtIndex:indexPath.row]urlString]]]]]; 
    cell.imageView.image = image; 
return cell; 
} 


- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier { 

    recentTweets = [[NSMutableArray alloc] init] ; 


    for(NSDictionary *d in statuses) { 

     NSLog(@"See dictionary: %@", d); 

     Tweet *tweet = [[Tweet alloc] initWithTweetDictionary:d]; 
     [recentTweets addObject:tweet ]; 
     NSLog(@"%@",[tweet author]); 
     NSLog(@"%@",[tweet urlString]); 



     [tweet release]; 


    } 

    [self.tableView reloadData]; 
} 

我想在一個視圖中顯示鳴叫的細節。如何將其傳遞給下一個視圖控制器

回答

0

避風港實例變量NSDictionary在您的第二個視圖控制器中鍵入。 @synthesize那個字典。

然後在你的當前類的代碼添加

yourSecondcontroller.dictionary = urDictionaryInCurrentClass; 
+0

@ user640780請投了答案,當你接受他們... – visakh7 2011-05-03 07:31:41

1

我想你可以分享Tweet爲你的下一個視圖的屬性,當你點擊一個單元格,然後通過你的第一個視圖到下一個視圖的鳴叫如 -

在NextView.h

在NextView.m

#import "Tweet.h" 

Tweet *tweet; 

@property (nonatomic, retain) Tweet *tweet; 

並在第一視圖表委託

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    Tweet *tweet = (Tweet*)[recentTweets objectsAtIndex:indexPath.row]; 
    NextView *nextView = [[NextView alloc] init]; 
    nextView.tweet = [tweet retain]; 
    [nextView release]; 
} 
相關問題