سؤال

افتراضيا هناك ثلاثة اختيار نمط في اي فون - عرض الجدول.

الرمادي - الأزرق - لا شيء.

أنا لست بحاجة إلى الرمادي أو الأزرق.

أريد أن مجموعة من عادتي.

على سبيل المثال في الوضع الطبيعي خلية يجب أن يكون "aaaa.png" الخلفية.

& الخلية المحددة يجب أن يكون "bbbbb.png" الخلفية.

لقد حاولت تطبيق الخلية.backgroundView & الخلية.selectedBackground الرأي.ومع ذلك فإنه لا يعمل.

إذا كان لديك أي فكرة عن هذا, الرجاء مساعدتي.

شكرا مقدما على مساعدتي.

هل كانت مفيدة؟

المحلول

وثلاثة خطوط للقانون هنا، ولكن لا تحتاج صورة!

UIView *selectedBackgroundViewForCell = [UIView new];
[selectedBackgroundViewForCell setBackgroundColor:[UIColor redColor]];
theCell.selectedBackgroundView = selectedBackgroundViewForCell;

نصائح أخرى

هنا طريقة واحدة للقيام بذلك مع فقط 1 سطر من التعليمات البرمجية:

cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pink.png"]] autorelease];

من الواضح أنك سوف تحتاج إلى جعل الصورة.

وحاولت التالية وأنه يعمل.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
NSString *CellIdentifier = [NSString stringWithFormat:@"%i",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    XML_FitnessPrograms *t=[arrayPrograms objectAtIndex:indexPath.row];
    cell=((indexPath.row%2)==0) ? 
    [self getCellContentView:CellIdentifier program_name:t.program_name alterNate:NO indexPath:indexPath] :
    [self getCellContentView:CellIdentifier program_name:t.program_name alterNate:YES indexPath:indexPath] ;
    CGRect a=CGRectMake(8, 0, 300, 44);
    UIImageView *aImg=[[UIImageView alloc] initWithFrame:a];
    UIImageView *bImg=[[UIImageView alloc] initWithFrame:a];
    aImg.image=[UIImage imageNamed:@"white-rect-tab.png"]; //arrow.png
    bImg.image=[UIImage imageNamed:@"white-rect-tab-copy.png"];
    [aImg setContentMode:UIViewContentModeScaleToFill];
    [bImg setContentMode:UIViewContentModeScaleToFill];
    cell.backgroundView=aImg;
    cell.selectedBackgroundView=bImg;
    [aImg release];
    [bImg release];
}
return cell;
}

-(UITableViewCell*)getCellContentView:(NSString*)cellIdentifier program_name:(NSString*)program_name alterNate:(BOOL)alterNate indexPath:(NSIndexPath*)indexPath
{

    UITableViewCell *cell; UILabel *tmp;
    CGRect label1Frame=CGRectMake(5, 0, 260, 44);
    cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
    cell.frame=CGRectMake(8, 0, 280, 44);
    cell.backgroundColor=[UIColor clearColor];
    tmp=[[UILabel alloc] initWithFrame:label1Frame]; 
    tmp.textColor=[UIColor colorWithRed:(9.0/255.0) green:(68.0/255) blue:(85.0/255) alpha:1.0];
    [tmp setFont:[UIFont fontWithName:@"Arial-BoldMT" size:15]];  
        tmp.text=program_name;                   
        [tmp setShadowColor:[UIColor lightGrayColor]];
    tmp.backgroundColor=[UIColor clearColor]; 
        [cell.contentView addSubview:tmp]; [tmp release];
    [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
    return cell;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top