2013-08-13 6 views
6

मैं अपने प्रोजेक्ट में "हटाने के लिए स्वाइप करें" विकल्प का उपयोग करना चाहता हूं।UITableView समस्याओं में विकल्प हटाने के लिए स्वाइप करें

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     NSDictionary *userData = [_contactsArray objectAtIndex:indexPath.row]; 
     NSLog(@"delete row %@",userData); 
    } 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return YES; 
} 

मैं इस कोड का उपयोग कर रहा हूं लेकिन यह निम्नलिखित आउटपुट देता है जो मैं नहीं चाहता हूं। enter image description here

मैं नहीं चाहता कि बाईं ओर शून्य पर साइन साइन करें। मैं बस स्वाइप करना चाहता हूं और हटाएं बटन दिखाएं। वही कोड मैंने अपने पिछले प्रोजेक्ट में उपयोग किया है और यह ठीक काम करता है (यानी केवल डिलीट बटन दिखाने के लिए स्वाइप करें, बाएं तरफ कोई शून्य चिह्न नहीं)

कृपया इसे हल करने में मेरी सहायता करें।

+0

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewCell/shouldIndentWhileEditing – Kevin

+0

http://stackoverflow.com/प्रश्न/3020 9 22/किसी भी तरह से-छिपाने-हटाने-बटन-जबकि-संपादन-uitableview – Rushabh

+0

आप सही UITableViewDelegate विधियों को ओवरराइड कर रहे हैं। लेकिन क्या आप अपने यूआईटीबल व्यू की 'संपादन' संपत्ति को अपने कोड में कहीं भी 'YES' पर सेट कर रहे हैं? यदि ऐसा है, तो इससे लाल ऋण संकेत दिखाई दे सकते हैं। – hgwhittle

उत्तर

9

आप 'स्वाइप करने के लिए स्वाइप करें' कार्यक्षमता के लिए सही प्रतिनिधि विधियों को ओवरराइड कर रहे हैं। इस तरह

self.yourTableView.editing = NO; 
//or simply remove this line of code altogether because this property is NO by default 

दिखाएँ ऋण चिह्न: इस तरह

छिपाएं ऋण चिह्न: शून्य से संकेत के बारे में

self.yourTableView.editing = YES; 
1

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

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 
0

लगता है कि आपने इतनी पंक्तियों ऋण चिह्न के साथ दिखाई पर tableView.editing झंडा बदल रहे हैं। self.tableView.editing = YES; के लिए खोज करने का प्रयास करें और इसे NO बनाएं या बस उस लाइन को टिप्पणी करें।

3

पहले कि करने के लिए अपने तालिका दृश्य और सेट प्रतिनिधि और डेटा स्रोत विधि पैदा करते हैं।

self.contacts=[[UITable alloc]init]; 
    self.contacts.dataSource=self; 
    self.contacts.delegate=self; 
    self.contacts.userInteractionEnabled=YES; 
    //self.contacts.editing = YES; 
    [self.view addSubview:self.contacts]; 

और फिर निम्न विधियों को ओवरराइड करने के लिए प्रतिनिधि और डेटा स्रोत विधियों को ओवरराइड करें।

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return YES if you want the specified item to be editable. 
     return YES; 
    } 

    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      //add code here for when you hit delete 
     }  
    } 

बाईं ओर उपयोग पर ऋण चिह्न के लिए self.contacts.editing = हाँ; मेरे मामले में मैं यह शून्य चिह्न नहीं चाहता हूं इसलिए बस उस संपत्ति का उपयोग न करें या self.contacts.editing = NO सेट करें;

आप hw731 मुझे इस संपत्ति याद दिलाने के लिए धन्यवाद, मैं इस पर मेरे आधे दिन व्यर्थ है।

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