2013-04-10 126 views
0

我想要获得一个添加按钮来添加行到一个表,然后可以编辑 我得到预期的标识符或'('行10, 17,和30以下是代码:期望的标识符或'('在xcode 4.6.1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
    UILabel *lblName = (UILabel *)[cell viewWithTag:100]; 
    [lblName setText:[intervalArray objectAtIndex:[indexPath row]]]; 
    return cell; 
} 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:CellIdentifier]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 


if ([indexPath section]) == 0 { 
    UITextField *workoutTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
    workoutTextField.adjustsFontSizeToFitWidth = YES; 
    workoutTextField.textColor = [UIColor blackColor]; 
    if ([indexPath row] == 0) { 
     workoutTextField.placeholder = @"..."; 
     workoutTextField.keyboardType = UIKeyboardTypeEmailAddress; 
     workoutTextField.returnKeyType = UIReturnKeyNext; 

}} 

// Configure the cell... 

return cell; 

我已经试过你的建议,他们摆脱了所有的错误,但我仍然无法行与按钮添加到我的餐桌任何建议。关于如何添加行到表中将不胜感激,这是我的第一个iOS应用程序,并且对于编程来说我是相当新的。感谢所有的帮助! 我正在使用OS X 10.8.3

回答

3

我觉得你在这里放错一个括号:

if ([indexPath section]) == 0 { 

你的意思是:

if ([indexPath section] == 0) { 

方括号在这里被包围方法调用消息发送给indexPath;圆括号包含条件比较您正在进行的操作是检查调用[indexPath section]的结果是否等于零。

编辑:你也可以有一个右大括号太快 - 第7行的}关闭你的方法-tableView:cellForRowAtIndexPath:的整个实施。您可能希望将其一直移动到您的return cell;声明之下。

+0

是的......你找到答案:) +1 – 2013-04-10 18:43:12

1

第10行和第17行的条件和第30行的return语句属于哪种方法?它们似乎卡在你的实现文件中,这使编译器感到困惑。

简单地移动结束-tableView:cellForRowAtIndexPath:的大括号将修复错误,但由于您正在返回第7行的值(结束方法的执行),所以其余代码将不会执行任何操作。