2011-05-28 6 views
12

हे, क्या कोई मुझे इस माध्यम से मार्गदर्शन कर सकता है मेरे पास तालिका में लगभग 15 प्रविष्टियां हैं I पिछले 15 में अंतिम UITableViewCell में लोड के साथ आने के लिए 15 अन्य पसंद करेंगे। क्या कोई मेरी मदद कर सकता है?uitableviewcell में "अधिक लोड करें" बटन बना रहा है?

+2

UITableView में ["अधिक लोड करें" के संभावित डुप्लिकेट] (http://stackoverflow.com/questions/4410257/) या ["लोड 25 अधिक" को कैसे कार्यान्वित करें] (http://stackoverflow.com/questions/ 2801069 /) या [मेल ऐप अधिक संदेश लोड करें] (http://stackoverflow.com/questions/4396464/) या [आईफोन में अधिक रिकॉर्ड लोड करें] (http://stackoverflow.com/questions/4965919/) या [जोड़ें तालिका दृश्य के लिए अधिक विकल्प लोड करें] (http://stackoverflow.com/questions/5898399/) [अन्य] के बीच (http://stackoverflow.com/search?q=iphone+load+more) –

उत्तर

19

tableview में एक अतिरिक्त पंक्ति को दिखाने के लिए,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return dataRows+1; 
    } 

में

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

     //after setting tableviewcell 

     if(indexPath.row==dataRows){ 

     [email protected]"Load More Rows"; 
     } 
    } 

में

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    if(indexPath.row==dataRows){ 
    //there you can write code to get next rows 
    } 
} 

में आप प्रदर्शित पंक्तियों के अनुसार चर numberOfRows अपडेट करना होगा।

संपादित करें: अतिरिक्त प्रविष्टियों को लाने के बाद, आप उन्हें निम्न विधि का उपयोग कर मौजूदा प्रविष्टियों सरणी में जोड़ सकते हैं। इस विधि का उपयोग करने के लिए आपकी मूल सरणी NSMutableArray होना चाहिए।

[originalEntriesArray addObjectsFromArray:extraEntriesArray];

+0

@ श्रीप्रिया, इसे जोड़ें लाइन 'संख्याऑफरो = [yourEntriesArray गिनती] + 1; 'इसे और स्पष्ट करने के लिए। – EmptyStack

+0

@ सिमॉन: नमस्ते .., मैंने कोड – SriPriya

+0

@SriPriya, Hmmm :) – EmptyStack

1

आशा है कि यह

मैं एक परिवर्त्य सरणी और एक पूर्णांक चर लिया और पूर्णांक चर

 
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; 
dataRows = [arr count]; 

और उसके बाद मैं संख्या निर्धारित करने वालों की कुल संख्या सेट में मदद करता है तालिका

 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return dataRows+1; 
} 
के डेटासोर्स विधि में पूर्णांक चर के अनुसार खंडों में पंक्तियों में से 210

क्योंकि आप अंत में एक अतिरिक्त सेल चाहते थे।

अब अपने समय

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ स्थिर NSString * CellIdentifier = @ "सेल" तालिका सेल का पाठ सेट करने के लिए;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 

//setting the text of the cell as per Mutable array 
if (indexPath.row < [arr count]) { 

    cell.textLabel.text = [arr objectAtIndex:indexPath.row]; 
} 

//setting the text of the extra cell 

if (indexPath.row == dataRows) { 
    cell.textLabel.text = @"more cells"; 
}  
return cell; 

}

अब और अधिक कोशिकाओं सेल के हिट पर

आप अतिरिक्त कोशिकाओं सही तो बस

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

विधि के अंदर अपना कोड जोड़ना चाहते हैं, मतलब है कि आप कुछ इस तरह करना है

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == dataRows) 
    { 
     //code for exra cells please 
    } 
} 

इस कोड को देखने के लिए अपने ऐप को चलाएं।

8

मैंने एक उदाहरण प्रोजेक्ट लिखा जो यह करता है। GitHub https://github.com/Abizern/PartialTable

+1

मुझे 'startUpdate' और' endUpdate' का उपयोग करके तालिका दृश्य को अपडेट करने का हिस्सा पसंद है –

4

से डाउनलोड मैं कुछ है कि उपयोगी हो सकता है लिखा है: https://github.com/nmondollot/NMPaginator

यह पृष्ठांकन समाहित है, और काफी किसी भी पेज और per_page मानकों का प्रयोग करके वेब सेवा के साथ काम करता है। जब आप नीचे स्क्रॉल करते हैं तो अगले परिणामों के स्वचालित फ़ेचिंग के साथ इसमें UITableView भी शामिल है।

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