2011-06-25 13 views
6

मेरे आवेदन में, मैं TableView के लिए समूहबद्ध शैली का उपयोग कर रहा हूं। उस में मैं सेल चयन शैली को कस्टमाइज़ करना चाहता हूं। मैं चाहता हूं कि चयन शैली लाल हो।आईफोन में UITableView में अनुकूलित सेल चयन शैली में समस्या

मुझे लगता है कि के लिए नीचे दिए गए कोड का उपयोग कर रहा:

UIView *bgColorView = [[UIView alloc] init]; 
[bgColorView setBackgroundColor:[UIColor redColor]; 

[cell setSelectedBackgroundView:bgColorView]; 
[bgColorView release]; 

उपरोक्त कोड का उपयोग करके। मुझे एक समस्या है। चूंकि मैंने पहली बार और आखिरी पंक्तियों के चयन में स्टाइल टेबल को समूहीकृत किया है, तो चयन के बजाय तीव्र किनारों वाले आयत के साथ दिखाई देता है।

क्या कोई इस में मेरी सहायता कर सकता है। अग्रिम में धन्यवाद।

उत्तर

3

इस प्रयास करें,

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

    static NSString *CellIdentifier = @"CellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectedCellBackground.png"]] autorelease]; 
    } 

    // Cell configuration takes place here 
} 
-2
UIImageView *imageVieww=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell2.bounds.size.width, cell2.bounds.size.height)]; 


    imageVieww.image=[UIImage imageNamed:@"mavilik.png"]; 

    [cell2 setSelectedBackgroundView:imageVieww]; 

    [imageVieww release]; 
0

अपने उप-वर्ग में -(void)setSelected:animated: ओवरराइड करें।

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    if (selected) 
    [self setBackgroundColor:[UIColor redColor]]; 
    else 
    [self setBackgroundColor:[UIColor whiteColor]]; 
} 

आप मिश्रण और चयन और अचयन पर पृष्ठभूमि बाहर फीका अगर animated हाँ है करने के लिए यहाँ फैंसी एनीमेशन जोड़ सकते हैं।

सामान्य में UITableViewCell उपclass के लिए थोड़ा अजीब हो सकता है, यहां धैर्य रखें।

1

क्वार्ट्जकोर फ्रेमवर्क जोड़ें। और .m फ़ाइल में QuartzCore/QuartzCore.h ढांचे आयात करें। और उसके बाद cellForRowAtIndexPath विधि में निम्न कोड जोड़ें।

UIImageView *imv = [[UIImageView alloc]init]; 
imv.backgroundColor=[UIColor redColor]; 
[cell setSelectedBackgroundView:imv]; 
CALayer *layer = imv.layer; 
[layer setMasksToBounds:YES]; 
[layer setCornerRadius:10.0]; 
[imv release]; 
संबंधित मुद्दे