Как передать значение NsDictionary для следующего представления из таблицы - PullRequest
1 голос
/ 03 мая 2011

Hii, я получаю значения в uitableview из класса модели, который имеет 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];
}

Я хочу отобразить детали твита в следующем представлении. Как передать это следующему контроллеру представления

Ответы [ 2 ]

1 голос
/ 03 мая 2011

Я думаю, что вы можете сделать Tweet свойством следующего просмотра, и когда вы щелкнете по ячейке, затем передадите твит вашего первого просмотра следующему представлению как -

в NextView.h

#import "Tweet.h"

Tweet *tweet;

@property (nonatomic, retain) Tweet *tweet;

в NextView.m

@synthesize 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];
}
0 голосов
/ 03 мая 2011

Переменная экземпляра Haven типа NSDictionary в вашем втором контроллере представления.@synthesize этот словарь.

Затем в вашем текущем классе добавьте код

yourSecondcontroller.dictionary = urDictionaryInCurrentClass;
...