2012-12-08 31 views
1

我想從這個格式的字符串開始的tableview「名1,鏈接1,姓名2,鏈接2 ......」 那麼我現在實際上做的是這樣的:的Xcode表視圖分裂

- 獲得的字符串,並把鏈接和名稱到一個數組,然後由對象

- (void)viewDidLoad 
{ 
NSString *dataString = @"a,www.google.it,b,www.apple.it,c,www.youtube.it"; 
dataArray = [dataString componentsSeparatedByString:@","]; 
for (int i=0; i<[dataArray count]; i++) { 
    if (i%2==0) { 
     [dataArrayName addObject:[dataArray objectAtIndex:i]]; 
    } 
    else { 
     [dataArrayLink addObject:[dataArray objectAtIndex:i]]; 
    } 
} 
[super viewDidLoad]; 
} 

- 設置了表視圖

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 

{ 
return [dataArrayName count]; 
} 

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

static NSString *MyIdentifier = @"myCell"; 

// Try to retrieve from the table view a now-unused cell with the given identifier. 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

// If no cell is available, create a new one using the given identifier. 
if (cell == nil) { 
    // Use the default cell style. 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"]; 
} 

// Set up the cell. 
NSString *cellName = [dataArrayName objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellName; 

return cell; 
} 

但是當的位置的陣列分成兩個更小的那些我跑步他用tableview查看應用程序的視圖很清晰(有空行) 問題是什麼?

+0

在IB,您是否正確連接的數據源和委託出口的table view? –

回答

0

你有沒有初始化dataArrayName和dataArrayLink(即,在某些時候,在你開始將對象添加到它,你剛纔說dataArrayName = [[NSMutableArray alloc] init]或等效?

+0

是的,在頭文件中... –

+0

你可能已經聲明瞭它('NSMutableArray * dataArrayName;'),但是你真的在.m中初始化它嗎?它們在Objective- C. – Max

+0

解決了。非常感謝。 –