2009-03-19 18 views
5

से भरें मेरे पास मेरे आईफोन एप्लिकेशन में एक एक्शनशीट पॉपअप है। मैं पूर्व निर्धारित मानों के बजाय इसे सरणी से तारों से भरना चाहता हूं।एक एक्शनशीट को एक सरणी

मुझे ऐसा करने के लिए ऑनलाइन कुछ भी नहीं मिल रहा है! शायद कार्यपत्रक उपयोग करने के लिए सही बात नहीं है? ,

roomspopup = [ [ UIActionSheet alloc ] 
        initWithTitle: alertname 
        delegate: self 
        cancelButtonTitle: @"Cancel" 
        destructiveButtonTitle: nil 
        otherButtonTitles: @"Kitchen", "Dining Room", nil ]; 

लेकिन बजाय "रसोई" और "भोजन कक्ष" मैं चाहता हूँ यह एक सरणी से भरने के लिए:

अभी यह है कि क्या मैं इसे बनाने की उपयोग कर रहा हूँ है। सरणी का आकार (यानी कमरों की संख्या) एक निश्चित संख्या नहीं है।

उत्तर

7

आप इसे एक लाइन में नहीं कर सकते हैं। आपको बटनों के खाली सेट के साथ initWithTitle पर कॉल करना होगा, और फिर addButtonWithTitle: का उपयोग करके अपने अन्य बटन लूप के साथ जोड़ें।

14

@JimTrell तरीका है कि ठीक करने के लिए रद्द करें बटन बिना UIActionSheet init और इस रद्द बटन जोड़ने के बाद आप अपने अन्य बटन जोड़ा होगा।

शून्य के एक समूह के साथ चादर init पहले:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose" 
         delegate:self 
         cancelButtonTitle:nil 
         destructiveButtonTitle:nil 
         otherButtonTitles:nil]; 

फिर addButtonWithTitle: और अंत के साथ अपने सरणी के माध्यम से लूप जोड़ने बटन रद्द करने और अपने सूचकांक सेट:

[actionSheet addButtonWithTitle:@"Cancel"]; 
[actionSheet setCancelButtonIndex:[yourArray count]]; 
+1

अधिक आम तौर पर: '[actionSheet setCancelButtonInd पूर्व: [actionSheet संख्याOfButtons] - 1]; ' – Nestor

0

मैं सेट कर सकते हैं इस कोड का उपयोग करके नीचे रद्द करें बटन:

anActionSheet = [[UIActionSheet alloc] initWithTitle:@"Change A/C" delegate:self 
    cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil]; 

for (int i = 0; i < [arraylist count]; i++)  
    [anActionSheet addButtonWithTitle:[arraylist objectAtIndex:i]]; 

anActionSheet.cancelButtonIndex = [arraylist count];  
[anActionSheet addButtonWithTitle:@"Cancel"]; 
+0

anActionSheet.cancelButtonIndex = [सरणी सूची गिनती]; मुख्य बिंदु है। यू लूपिंग के बाद इसे घोषित करने के लिए एचवी करेगा ताकि अन्य सभी बटनों के बाद रद्द बटन स्थापित किया जा सके। –