2011-08-15 21 views
5

मैं आईओएस की दुनिया में नया हूं और मैं जानना चाहता हूं कि UITableView को कस्टम सेल के साथ कैसे बनाना है, जो आपके पास कुछ वाईफाई कनेक्शन कॉन्फ़िगर करने का प्रयास करते समय आपके जैसा दिखता है और व्यवहार करता है डिवाइस। (आप UITableView को UITextField एस वाले ब्लू फ़ॉन्ट के साथ UITableView जानते हैं जहां आपने आईपी पता और सभी चीजें सेट की हैं ...)।प्रत्येक सेल पर एक टेक्स्टफील्ड के साथ संपादन योग्य UITableView

उत्तर

9

एक कस्टम सेल लेआउट बनाने के लिए कोडिंग का थोड़ा सा हिस्सा शामिल है, इसलिए मुझे उम्मीद है कि आपको डराना नहीं होगा।

पहली बात एक नया UITableViewCell सबक्लास बना रही है। आइए इसे InLineEditTableViewCell पर कॉल करें। आपका इंटरफेस InLineEditTableViewCell.h कुछ इस तरह दिखाई दे सकता है:

#import <UIKit/UIKit.h> 

@interface InLineEditTableViewCell : UITableViewCell 

@property (nonatomic, retain) UILabel *titleLabel; 
@property (nonatomic, retain) UITextField *propertyTextField; 

@end 

और अपने InLineEditTableViewCell.m ऐसा दिखाई दे सकता:

#import "InLineEditTableViewCell.h" 

@implementation InLineEditTableViewCell 

@synthesize titleLabel=_titleLabel; 
@synthesize propertyTextField=_propertyTextField; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Here you layout your self.titleLabel and self.propertyTextField as you want them, like they are in the WiFi settings. 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [_titleLabel release], _titleLabel = nil; 
    [_propertyTextField release], _propertyTextField = nil; 
    [super dealloc]; 
} 

@end 

अगला बात आप सेट-अप अपने UITableView है आप सामान्य रूप से आपके विचार नियंत्रक में प्रदर्शित होंगे। ऐसा करने पर आपको UITablesViewDataSource प्रोटोकॉल विधि - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath लागू करना होगा। इसके लिए अपना कार्यान्वयन डालने से पहले, अपने व्यू कंट्रोलर में #import "InLineEditTableViewCell" को याद रखें। ऐसा करने के बाद कार्यान्वयन निम्नानुसार है:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    InLineEditTableViewCell *cell = (InLineEditTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"your-static-cell-identifier"]; 

    if (!cell) { 
     cell = [[[InLineEditTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"your-static-cell-identifier"] autorelease]; 
    } 

    // Setup your custom cell as your wish 
    cell.titleLabel.text = @"Your title text"; 
} 

यही है! अब आपके पास UITableView में कस्टम कक्ष हैं।

शुभकामनाएं!

+3

आपकी मदद के लिए धन्यवाद। असल में मैं कोडिंग से डरता नहीं हूं, मैं ग्राफिक तत्वों में हेरफेर करने में अच्छा नहीं हूं :) – Zak001

संबंधित मुद्दे