2011-05-03 60 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]; 
} 
相关问题