के साथ कस्टम UITableViewCell बनाने के लिए IOS चरण ग्राफ़िक इंटरफ़ेस को आकर्षित करने के लिए मुझे xib फ़ाइल का उपयोग करके अपना स्वयं का UITableViewCell बनाना होगा ... मेरी नई कक्षा बनाने और मेरे UITableView में उपयोग करने के लिए सही कदम क्या हैं? अग्रिमxib फ़ाइल
उत्तर
एक video tutorial कैसे Xcode 4.2 के साथ ऐसा करना दिखाने में
धन्यवाद किया गया है। लेखक ने blog post भी लिखा है।
व्यक्तिगत रूप से मुझे लगता है कि reuseIdentifier
की बात आने पर दोनों सुझाए गए ट्यूटोरियल में बड़ी कमी है। यदि आप इसे इंटरफ़ेस बिल्डर या इसे गलत तरीके से असाइन करना भूल जाते हैं, तो आप हर बार cellForRowAtIndexPath
कहलाते हैं।
जेफ लामारे इस बारे में लिखते हैं और इसे blog post में कैसे ठीक करें। reuseIdentifier
के अलावा वह Loading Custom Table-View Cells From Nib Files पर सेब दस्तावेज़ों के समान दृष्टिकोण का उपयोग करता है।
इन सभी लेख मैं निम्नलिखित कोड के साथ आया था पढ़ा होने के बाद:
संपादित करें: आपके पास iOS 5.0 लक्षित कर रहे हैं और उच्च आप Duane Fields' answer
@interface CustomCellWithXib : UITableViewCell
+ (NSString *)reuseIdentifier;
- (id)initWithOwner:(id)owner;
@end
@implementation CustomCellWithXib
+ (UINib*)nib
{
// singleton implementation to get a UINib object
static dispatch_once_t pred = 0;
__strong static UINib* _sharedNibObject = nil;
dispatch_once(&pred, ^{
_sharedNibObject = [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
});
return _sharedNibObject;
}
- (NSString *)reuseIdentifier
{
return [[self class] reuseIdentifier];
}
+ (NSString *)reuseIdentifier
{
// return any identifier you like, in this case the class name
return NSStringFromClass([self class]);
}
- (id)initWithOwner:(id)owner
{
return [[[[self class] nib] instantiateWithOwner:owner options:nil] objectAtIndex:0];
}
@end
UINib साथ रहना चाहता हूँ अगर (आईओएस 4.0 और बाद में उपलब्ध) का उपयोग यहां सिंगलटन के रूप में किया जाता है, क्योंकि reuseIdentifier
का उपयोग किया जाता है, फिर भी सेल को लगभग 10 गुणा या फिर शुरू किया जाता है।
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCellWithXib *cell = [tableView dequeueReusableCellWithIdentifier:[CustomCellWithXib reuseIdentifier]];
if (cell == nil) {
cell = [[CustomCellWithXib alloc] initWithOwner:self];
}
// do additional cell configuration
return cell;
}
iOS5 में आप नए का उपयोग करना चाहेंगे:
registerNib:forCellReuseIdentifier
:
कौन सा मूल रूप से एक ही बात करता है ...
आप बना सकते हैं अब cellForRowAtIndexPath
इस तरह दिखता है XIB के साथ कस्टमसेल क्लास जिसे UITableViewCell से विरासत में मिला है। हम टेबलव्यू क्लास। एम फ़ाइल में निम्नलिखित तरीके से श्रेणी जोड़ देंगे। मुझे लगता है कि यह सबसे आसान तरीका है जिसे कस्टम सेल निर्माण के लिए लागू किया जाना चाहिए।
@interface UITableViewCell(NIB) @property(nonatomic,readwrite,copy) NSString *reuseIdentifier; @end - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 30; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *[email protected]"cell"; CustomCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier]; if(cell==nil) { NSLog(@"New Cell"); NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; cell=[nib objectAtIndex:0]; cell.reuseIdentifier=identifier; }else{ NSLog(@"Reuse Cell"); } cell.lbltitle.text=[NSString stringWithFormat:@"Level %d",indexPath.row]; id num=[_arrslidervalues objectAtIndex:indexPath.row]; cell.slider.value=[num floatValue]; return cell; } @end
इस ट्यूटोरियल समाप्त करने के लिए सेल की xib और वर्ग फ़ाइलों सभी तरह बनाने की प्रक्रिया से पूरे आधुनिक iOS 5 समाधान के माध्यम से ले जाता है,:
`आप बना सकते हैं .xib फ़ाइल की मदद से तालिका दृश्य में कस्टम कक्ष। सबसे पहले अपने दृश्य नियंत्रक में तालिका दृश्य सेट करें, अपनी कक्षा के साथ एक नई xib फ़ाइल बनाएं और इसे तालिका दृश्य में उपयोग करें।
- (IBAction)moveToSubCategory:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *foodCategoryLabel;
@property (strong, nonatomic) IBOutlet UIImageView *cellBg;
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [foodCatArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ExampleCell";
ExampleCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExampleCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[cell setTag:indexPath.row];
cell.cellBg.image=[UIImage imageNamed:[photoArray objectAtIndex:indexPath.row]];
cell.foodCategoryLabel.text=[foodCatArray objectAtIndex:indexPath.row];
return cell;
}
- 1. एक xib फ़ाइल
- 2. .xib
- 3. XIB
- 4. .xib
- 5. XIB
- 6. एक Xib
- 7. मैं xib
- 8. एकाधिक "फ़ाइल के मालिक" के साथ एक xib फ़ाइल
- 9. बाहरी xib
- 10. अभिभावक XIB
- 11. xib फ़ाइलें
- 12. कठिनाई लोकलाइजिंग xib फ़ाइलें
- 13. .xib फ़ाइल और .storyboard के बीच क्या अंतर है?
- 14. xib फ़ाइल के विलय संघर्ष को कैसे हल करें?
- 15. आईओएस प्रोजेक्ट में XIB फ़ाइल का उत्तराधिकारी कैसे प्राप्त करें?
- 16. इनहेरिट UIViewController वर्ग और XIB
- 17. एक्सकोड: इंटरफ़ेस बिल्डर XIB
- 18. किसी अन्य xib
- 19. .xib और बैकिंग क्लास
- 20. Xcode 4.5 XIB दूषित?
- 21. एक्सकोड - XIB को ViewController क्लास
- 22. आईओएस और अनारकिंग xib फाइलें
- 23. xib फ़ाइलों में आईओएस कस्टम दृश्य
- 24. किसी अन्य xib में दृश्य के अंदर एक xib से UIViewController के दृश्य को कैसे एम्बेड करें?
- 25. xib से स्टोरीबोर्ड को कैसे परिवर्तित करें?
- 26. UISplitViewController प्रोग्राम के बिना nib/xib
- 27. setStatusBarHidden: NO XIB लोड के बाद UINavigationBar
- 28. मोनो टच/मोनो डेवलप: xib-files
- 29. मैं प्रत्येक भाषा के लिए xib बनाये बिना xib दृश्यों में टेक्स्ट को कैसे स्थानांतरित कर सकता हूं?
- 30. हटाए गए xib को कैसे लोड किया जाता है?
मेरी राय में, यह सबसे अच्छा तरीका है। इसके लिए धन्यवाद। अगर यह मेरा विषय था, तो मैं इसे प्रतिक्रिया के रूप में चिह्नित करूंगा। –