博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

loadNibNamed 的使用

Posted on 2011-05-16 18:07  BradyChen  阅读(4223)  评论(0编辑  收藏  举报
感觉很怪怪的

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

{

    static NSString *CellIdentifier = @"ApplicationCell";

    ApplicationCell *cell = (ApplicationCell *)[tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

#if USE_INDIVIDUAL_SUBVIEWS_CELL

        [[NSBundle mainBundleloadNibNamed:@"IndividualSubviewsBasedApplicationCell" owner:self options:nil];

        cell = tmpCell;

        self.tmpCell = nil;

#elif USE_COMPOSITE_SUBVIEW_CELL

        cell = [[[CompositeSubviewBasedApplicationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ApplicationCell"autorelease];

#elif USE_HYBRID_CELL

        cell = [[[HybridSubviewBasedApplicationCell allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ApplicationCell"autorelease];

#endif

    }

// Display dark and light background in alternate rows -- see tableView:willDisplayCell:forRowAtIndexPath:.

    cell.useDarkBackground = (indexPath.row % 2 == 0);

// Configure the data for the cell.

    NSDictionary *dataItem = [data objectAtIndex:indexPath.row];

    cell.icon = [UIImage imageNamed:[dataItem objectForKey:@"Icon"]];

    cell.publisher = [dataItem objectForKey:@"Publisher"];

    cell.name = [dataItem objectForKey:@"Name"];

    cell.numRatings = [[dataItem objectForKey:@"NumRatings"intValue];

    cell.rating = [[dataItem objectForKey:@"Rating"floatValue];

    cell.price = [dataItem objectForKey:@"Price"];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}

另外一个小朋友写的代码

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

{

static NSString *SimpleTableIdentifier = @"STI_SongsInfoCell";  //SimpleTableIdentifier

//定义"视图闲置组"标识符,可以是任意字符串,只要不冲突即可

myMusicInfoCellClass *cell = (myMusicInfoCellClass*)[tableViewdequeueReusableCellWithIdentifier:SimpleTableIdentifier];

//创建一个视图,从标识为"STI"的闲置视图组中。

//如果"STI"中有可用的闲置视图,则返回一个UITableViewCell,否则返回nil

if (cell == nil) {   //如果cell=nil , 则表示sti中没有可用的闲置视图

//创建一个视图,表示这个同STI组里面的组是同一种类型

NSArray *nib = [[NSBundle mainBundleloadNibNamed:@"SongsInfoCell" owner:self options:nil];

for (id oneObject in nib) 

if ([oneObject isKindOfClass:[myMusicInfoCellClass class]]) 

cell = (myMusicInfoCellClass*)oneObject;

};

//到这里为止,UITableViewCell就创建好了呃,下面就用它

NSUInteger row = [indexPath row];

//NSLog(@"test = %@",SearchSongsList);

if ([SearchSongs objectAtIndex:row]==nil) {

return nil;

}

//设置celllabel标签

NSArray * myArr =  [[SearchSongs objectAtIndex:row] componentsSeparatedByString:@"<分割>"];

//判断是否存在于播放列表之中,以确定AddedBtn是否可用

BOOL isAlreadyAdded = NO;

for (int i=0; i<[[myTbc playListcount]; i++) {

if ([[[[myTbc playListobjectAtIndex:i] objectAtIndex:3isEqualToString:[myArrobjectAtIndex:3]]

) {

isAlreadyAdded = YES;

}

}

if (isAlreadyAdded==YES) {

cell.AddedBtn.enabled = NO;

else {

cell.AddedBtn.enabled = YES;

}

cell.SongsName.text = [myArr objectAtIndex:0]; //myArr数组里取元素

cell.SongsSinger.text = [myArr objectAtIndex:1];

cell.SongsAlbum.text = [myArr objectAtIndex:2];

cell.SongsInfo = (NSMutableArray*)myArr;

if ([[myArr objectAtIndex:4hasSuffix:@".gif"]) {

if ([[myArr objectAtIndex:4hasPrefix:@"d"]) 

cell.SongsSpeed.image= [UIImage imageNamed:[myArr objectAtIndex:4]];

};

cell.SongsSize.text = [myArr objectAtIndex:5];

cell.myPlayListTableView = myPlayListTableView;

cell.myTbc = myTbc;

cell.mySc = self;

if ([myPlayer.nowPlayDownPageURL isEqualToString:[myArr objectAtIndex:3]]) {

myPlayer.WorkingIndicatorView=cell.myaiv;

}

return cell;

}