2014年3月28日 星期五

tableViewCell如果沒有給他textLabel的文字會視為nil

/*
tableViewCell如果沒有給他textLabel的文字,給空字串(@"")也一樣
在這裡讀到的textLabel會是nil
而不是沒有文字的textLabel
*/

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

   //因此如果我們要比對文字的話,要先給他一個文字(這裡是給空格)
   if( !cell.textLabel.text )
    {
        cell.textLabel.text = @" ";
    }
}

沒有留言:

張貼留言