iPhone: UITextField के साथ एक सेल का दृष्टिकोण की जगह

वोट
0

commitEditingStyle: मैं मूल रूप से tableView पर एक UITableViewCell के लिए एक UITextField जोड़ने के लिए कोशिश कर रहा हूँ forRowAtIndexPath :. डालने पर, मैं मौजूदा कक्ष पर एक UITextField जोड़ना चाहते हैं।

मैं सेटअप कुछ इस तरह के साथ पाठ फ़ील्ड:

-(void) setUpIndexField {
    inputField = [[UITextField alloc] init];
    inputField.textAlignment = UITextAlignmentCenter;
    inputField.borderStyle = UITextBorderStyleRoundedRect;    
    inputField.keyboardType = UIKeyboardTypeNamePhonePad;
    inputField.delegate = self;
 }

तब commitEditingStyle में, मैं इस तरह के रूप कुछ है:

- (void)tableView:(UITableView *)tv
    commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
    forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSInteger row = [indexPath row];
    if (editingStyle == UITableViewCellEditingStyleInsert) {
    if (row == 0) {
        UITableViewCell *cell = [tv cellForRowAtIndexPath:indexPath];
        inputField.frame = [tv cellForRowAtIndexPath:indexPath].frame;
        [cell.contentView addSubview:inputField];
        [inputField becomeFirstResponder];
        return;
    }
// more code etc.
}

जब मैं सम्मिलित एक्सेसर (+) पर क्लिक करें, पाठ फ़ील्ड वास्तव में स्क्रीन पर plopped हो जाता है, लेकिन सेल जाता है कि उस पर क्लिक करने के पास कोई जहां। यह UIView, जहां + क्लिक किया गया था पर indexPath के लिए न कि वास्तविक सेल के एक यादृच्छिक भाग में बंद हो जाता है।

मैं कहाँ गलत हो गया था पर इनसाइट और कैसे मैं सेल जहां + आदर्श होगा क्लिक किया गया था पर UITextField रख सकते हैं।

23/02/2009 को 22:42
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

वोट
1

आप के फ्रेम सेट कर रहे हैं inputFieldसेल के फ्रेम जो आप क्या चाहते हैं नहीं करेंगे करने के लिए। सेल के अंदर दृश्य के रूप में फ्रेम के ऊपरी बाएँ का उपयोग 0,0। आपका पाठ फ़ील्ड फ्रेम किया जाना चाहिए:

inputField.frame = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height);

चूंकि कि superview कि पाठ फ़ील्ड स्थापित करेंगे तो यह यह पूरी तरह से है कि सेल में अन्य दृश्यों को शामिल किया गया यह के सापेक्ष है।

23/02/2009 को 22:50
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more