我有一个主表视图和一个详细视图。当我单击单元格详细信息视图时,应显示该项目的详细信息。现在我想做的是创建子视图并将该子视图放在detailView中,而不是为每个单元格创建一个detailview。它会解决我的一些其他问题。代码如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *nextController = [[DetailViewController alloc] init];
int storyIndex = [indexPath indexAtPosition:[indexPath length] -1];
[nextController initWithObjectAtIndex:storyIndex inArray:stories];
NSString *storyTitle = [[stories objectAtIndex:storyIndex] objectForKey:@"title"];
nextController.title = @"Details";
UIBarButtonItem *tempButtonItem = [[[UIBarButtonItem alloc] init] autorelease];
tempButtonItem.title = @"Tillbaka";
self.navigationItem.backBarButtonItem = tempButtonItem ;
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}
现在如何创建带有标签的子视图并将该标签的文本更改为storyTitle。 提前完成。
答案 0 :(得分:1)
如何创建带有标签的子视图并将该标签的文本更改为storyTitle
给定父视图,您不需要创建新的子视图只是为了向父级添加标签。但是,假设您确实想要在父视图中添加带有标签的子视图,请执行以下操作:
...
UIView *parentView;
...
UIView *subView = [[[UIView alloc] initWithFrame:mySubViewFrame] autorelease];
UILabel *lbl = [[[UILabel alloc] initWithFrame:myLabelFrame] autorelease];
lbl.text = storyTitle;
[subView addSubview: lbl];
[parentView addSubview: subView];