我有2个视图,都是表视图 第一视图 列表存在,所以当用户点击特定的单元格时,我想采取选定单元格的文本和存储进入变量并按下第二个视图如何从表中的单元格文本到字符串
例如stringVariable = cell.text
第二视图
现在我想通过使用stringVariable可变
例如设置的视图标题self.title = stringVariable;
我希望有人知道这个问题
预先感谢您
我有2个视图,都是表视图 第一视图 列表存在,所以当用户点击特定的单元格时,我想采取选定单元格的文本和存储进入变量并按下第二个视图如何从表中的单元格文本到字符串
例如stringVariable = cell.text
第二视图
现在我想通过使用stringVariable可变
例如设置的视图标题self.title = stringVariable;
我希望有人知道这个问题
预先感谢您
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Save text of the selected cell:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
stringVariable = cell.textLabel.text;
// load next view and set title:
MyView *nextView = [[MyView alloc] initWithNibName:@"MyView" bundle:nil];
nextView.title = stringVariable;
[self.navigationController pushViewController:nextView animated:YES];
}
您必须使用一些阵列的数据来填充表视图。
例如。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
TableItem * tableItem = [tableItems objectAtIndex:indexPath.row];
UILabel mainLabel = [[UILable alloc] initWithFrame:()];
mainLabel.text = tableItem.name;
[cell.contentView addSubView:mainLabel];
[mainLabel release];
return cell;
}
同样,您应该使用相同的阵列来获得所需的项目,选择它的
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TableItem * tableItem = [tableItems objectAtIndex:indexPath.row];
OtherViewController * otherViewController = [[OtherViewController alloc] init];
otherViewController.name = tableItem.name;
[self.navigationController pushViewController:otherViewController animated:YES];
[otherViewController release];
}
非常感谢你曼尼 – Pooja 2011-03-10 13:58:30