2009-06-10 64 views
0

我想添加一個子視圖到tableview單元格,當然還要使用CGRect作爲它的一部分。不過,我得到的構建語法錯誤:嘗試使用CGRect的語法錯誤

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    switch (indexPath.section) { 
     case 1: 
      CGRect <<- SYNTAX ERROR cellFrame = CGRectMake(0, 0, 300, 65); 
      cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier: CellIdentifier] autorelease]; 

      CGRect infoRect = CGRectMake(0, 5, 295, 55); 
      UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoRect]; 
      infoLabel.tag = 1; 
      [cell.contentView addSubview:infoLabel]; 
      [infoLabel release]; 
      break; 
     default: 
      break; 
    } 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 

我已經試過框架上單擊鼠標右鍵 - >添加現有的框架,並沒有出現提供幫助。我想這似乎是編譯器仍然沒有看到框架?

編輯:其實我只是注意到CoreGraphics.framework實際上已經加載到項目中了。所以我現在很困惑。

+0

你得到了什麼錯誤? – stefanB 2009-06-10 22:31:13

回答

7

聲明cellFrameswitch聲明之外:

CGRect cellFrame;
switch (indexPath.section) {
case 1:
cellFrame = CGRectMake(0, 0, 300, 65);
break;
...
}

或把它周圍的括號:

switch (indexPath.section) {
case 1:
{ CGRect cellFrame = CGRectMake(0, 0, 300, 65); }
break;
...
}

+0

好傷心,你在開玩笑吧。 我愛Objective-C,我愛Objective-C ..... – kindaran 2009-06-11 03:45:08