loadNibNamed 的使用

loadNibNamed 的使用

|  No Comments  |  No TrackBacks
原文地址: http://iphone.ipsw.info/2010/02/loadnibnamed.html

感觉很怪怪的

- (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:selfoptions: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:UITableViewCellStyleDefaultreuseIdentifier:@"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:selfoptions: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;

}


No TrackBacks

TrackBack URL: http://iphone.ipsw.info/mt/mt-tb.cgi/292

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值