更新:
我有一个tableview
,里面有一些静态单元格。我想获取“Selected Cell”的textLabel
并希望将其分配给NSString
属性。
有什么建议吗?
答案 0 :(得分:0)
您不需要检查每个indexPath的值。尝试类似:
cell.titleLabel.text = [NSString stringWithFormat: @"World %d", indexPath.row];
答案 1 :(得分:0)
1)定义NSArray属性,
@property(nonatomic, strong) NSArray *titlesArray;
2)将标题添加到数组中,
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.titlesArray = [[NSArray alloc] initWithObjects:@"Title 1",@"Title 2",@"Title 3",@"Title 4",@"Title 5",@"Title 6",@"Title 7", nil];
}
3)像这样使用它们,
- (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];
}
cell.textLabel.text = [self.titlesArray objectAtIndex:[indexPath row]];
return cell;
}
答案 2 :(得分:0)
答案:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Now you can use cell.textLabel.text to get the title text of the selected static cell and assign it to your Property.
NSString *yourStr = cell.textLabel.text;
}