Hii,我从具有NsDictionary的模型类中获取uitableview中的值。这是我的代码
- (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 :(得分:1)
我认为您可以将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];
}
答案 1 :(得分:0)
第二个视图控制器中的NSDictionary
类型的Haven实例变量。 @synthesize
那本字典。
然后在当前的课程中添加代码
yourSecondcontroller.dictionary = urDictionaryInCurrentClass;