के साथ परिवर्तन IITableView सेल में टेक्स्ट फ़ील्ड की स्थिति की गणना करने के लिए cell.contentView.bounds.size.width
का उपयोग करता हूं। जब सेल बनाया जाता है, डीबग कोड चौड़ाई को 302 के रूप में रिपोर्ट करता है। जब सेल स्क्रीन से स्क्रॉल करता है और फिर वापस चालू होता है, तो डीबग कोड रिपोर्ट करता है कि यह 280 है - हर बार। ऐसा लगता है कि यह 302 पर वापस नहीं जाना चाहता है और 280 पर अटक गया है। शुद्ध परिणाम यह है कि टेक्स्ट फ़ील्ड को दूसरी जगह फ़ील्ड को सेल की सामग्री में डाल दिया जाता है, हालांकि इसे देखा गया था, हालांकि इसे पहली बार सही जगह।UITableView cell.contentView.bounds.size.width सेल रीयूज
मुझे लगता है कि 22 किसी भी तरह महत्वपूर्ण है, लेकिन मुझे नहीं पता कि यह क्या है। अनुमान लगाया जा सकता है कि यह प्रकटीकरण तीर हो सकता है, मैंने चौड़ाई निर्धारण के सामने "सेल साफ़ करें" कोड को स्थानांतरित किया, जिसमें नाडा के सहायक को सेट करना शामिल था।
क्या कोई मुझे बता सकता है कि यहां क्या हो रहा है?
(- मैं के बारे में पता है कि - अप्रासंगिक साथ सामान बाहर कतरना) कोड इस तरह दिखता है:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
while([cell.contentView.subviews count]){
id subview = [cell.contentView.subviews objectAtIndex:0];
[subview removeFromSuperview];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
8< snip!
CGFloat theCellWidth = cell.contentView.bounds.size.width - 44.0;
CGFloat theLineHeight = [[UIFont boldSystemFontOfSize: [UIFont labelFontSize]+1.0] lineHeight];
NSLog(@"cell.contentView.bounds.size.width %1.0f",cell.contentView.bounds.size.width);
if (0==section) {
switch (row) {
case 2:
while([cell.contentView.subviews count]){
id subview = [cell.contentView.subviews objectAtIndex:0];
[subview removeFromSuperview];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @" ";
cell.detailTextLabel.text = @"The Age";
theAgeTextField.frame = CGRectMake(10.0, 2.0, theCellWidth, theLineHeight);
// NSLog(@"cell.contentView %@",cell.contentView);
theAgeTextField.text = theAge;
theAgeTextField.font = [UIFont boldSystemFontOfSize: [UIFont labelFontSize]+1.0];
theAgeTextField.keyboardType = UIKeyboardTypeDecimalPad;
theAgeTextField.borderStyle = UITextBorderStyleNone;
theAgeTextField.userInteractionEnabled = NO;
[cell.contentView addSubview:theAgeTextField];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
8< snip! (lots of closing braces and other stuff omitted)
return cell;
}
घर, लड़कों और लड़कियों पर इस एक कोशिश करना चाहते हैं?
एक नए नेविगेशन-आधारित एप्लिकेशन के साथ शुरू करें। RootViewController.m में निम्नलिखित कोड डालें:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSLog(@"cell.contentView.bounds.size.width %1.0f",cell.contentView.bounds.size.width);
// Configure the cell.
return cell;
}
ऐसा करने के लिए आवश्यक डिफ़ॉल्ट कोड में केवल दो बदलाव हैं: अनुभाग में पंक्तियों की संख्या को बदलने ("वापसी 5") और की शैली सेल होना चाहिए UITableViewCellStyleSubtitle। तब, जब आप इस कार्यक्रम चलाने के लिए, आप इस के पांच लाइनों देखेंगे:
2011-06-18 11:10:19.976 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
2011-06-18 11:10:19.978 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
2011-06-18 11:10:19.979 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
2011-06-18 11:10:19.980 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
2011-06-18 11:10:19.982 TestTableCells[7569:207] cell.contentView.bounds.size.width 302
खींचें कुछ कोशिकाओं स्क्रीन बंद (ऊपर खींचें - नीचे कुछ भी नहीं है) और जब वे फिर से प्रकट होना, तो आप इस मिल :
2011-06-18 11:10:24.013 TestTableCells[7569:207] cell.contentView.bounds.size.width 320
2011-06-18 11:10:24.047 TestTableCells[7569:207] cell.contentView.bounds.size.width 320
2011-06-18 11:10:24.130 TestTableCells[7569:207] cell.contentView.bounds.size.width 320
सच कहूं, मैं इस के साथ बिल्ली के रूप में निराश हूँ, और इसलिए बहुत (, एक काम एप्लिकेशन के बिना भी) $ 99 टट्टू करने के लिए परीक्षा रहा हूँ तो मैं एप्पल पर किसी को इस पर में वजन हो सकता है।
किसी को भी कोई विचार है कि यहां क्या हो रहा है?
धन्यवाद!
कुछ और दिलचस्प देखना चाहते हैं?
NSString *CellIdentifier = [NSString stringWithFormat: @"%d", arc4random() ];
NSLog(@"%@",CellIdentifier);
अब, हर बार, लॉग में चौड़ाई है हमेशा 302. यह प्रतीत होता है, तो, एक पुन: उपयोग सेल मूल सेल की तुलना में अलग सामग्री की चौड़ाई है: static NSString...
लाइन के स्थान पर इस प्रयास करें ।
फिर ... सोच रहा है ... किसी को कोई सुराग मिला है?
मैंने एक समान समस्या देखी है, जिससे मैं प्रत्येक सेल को ढाल के साथ वापस करने के लिए एक CAGradientLayer बनाने के लिए UITableViewCell सीमाओं का उपयोग कर रहा हूं। जबकि आईपैड पोर्ट्रेट मोड में है, मैं सेल के दाईं ओर सफेद बक्से देखता हूं, जहां सेल की चौड़ाई लैंडस्केप ओरिएंटेशन चौड़ाई के रूप में पंजीकरण कर रही है। एक बार टेबल स्क्रॉल और कोशिकाओं का पुन: उपयोग किया जाता है, तो कोशिकाएं पंजीकृत होती हैं कि वे पोर्ट्रेट अभिविन्यास में हैं और सही चौड़ाई उठाते हैं। अभी भी इसे ठीक करने के तरीके को देख रहे हैं! – robotpukeko