问题描述请看视频,注意最后一行,用didSelectedRowAtIndex查选中行的文字,输出是正确的,但显示的却不是row 0或者row 1的文字,谢谢。
代码:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView
*)tableView {
// Return the number of sections.
return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [[[JINGMicroBlogStore sharedStore]allMicroBlogs]count]; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath {
static NSString *CellIdentifier = @"UITableViewCellDefault";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
textView=[[UILabel alloc]initWithFrame:CGRectZero];
[textView setTextColor:[UIColor blackColor]];
[textView setFont:[UIFont fontWithName:@"Helvetica" size:12.0f]];
[textView setBackgroundColor:[UIColor clearColor]];
[textView setTag:1];
//[textView setEditable:NO];
textView.numberOfLines=0;
[[cell contentView]addSubview:textView];
NSLog(@"%d",[indexPath row]);
}
NSString *statue=[[[[JINGMicroBlogStore sharedStore]allMicroBlogs]objectAtIndex:[indexPath row]]statueText];
CGSize constraint=CGSizeMake(320-(10*2),
99999.0f);
CGSize size=[statue sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
[textView setText:statue];
[textView setFrame:CGRectMake(10, 10, 320-(10*2),MAX(size.height,
44.0f))];
return cell; }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath{
NSString *statue=[[[[JINGMicroBlogStore sharedStore]allMicroBlogs]objectAtIndex:[indexPath row]]statueText];
//[[[statuses objectAtIndex:[indexPath row]] objectForKey:@"retweeted_status"]objectForKey:@"text"];
CGSize constraint = CGSizeMake(320 - (10 * 2), 20000.0f);
CGSize size = [statue sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
CGFloat height = MAX(size.height, 44.0f);
return height + (10 * 2); }
Update: 解决方法是cell用initWithFrame