2009-08-12 6 views
8

सेल इस कोड में कुछ भी क्यों नहीं दिखाता है:आईफोन एसडीके: UITableViewCell को UIActivityIndicatorView जोड़ना

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
[cell.imageView addSubview:spinner]; 
[spinner startAnimating]; 
[email protected]"Carregando..."; 
[spinner release]; 

मैं tableView:cellForRowAtIndexPath: के अंदर ऐसा कर रहा हूं।

मैंने फिट करने के लिए आकार की कोशिश की, cell.imageView के लिए एक फ्रेम बनाएं और स्पिनर के लिए एक ही आकार का फ्रेम बनाएं, लेकिन कुछ भी काम नहीं करता है।

इस कोड के साथ क्या गलत है?

धन्यवाद ..!

+0

आप गतिविधि सूचक के फ्रेम की स्थापना कर रहे हैं? कुछ spinner.frame = CGRectMake (0, 0, 30, 30) की तरह कुछ? आप सेल की छवि और दृश्यता को भी देख सकते हैं। छवि स्वयं देखें। – Tyler

+0

हां, मैंने दोनों स्पिनर फ्रेम बनाए और अपनी दृश्यता स्थापित की ... लेकिन मुझे जवाब मिला क्योंकि मैंने बेलो का वर्णन किया ... मदद के लिए धन्यवाद ..! – Thiago

उत्तर

3

मुझे लगता है कि सेल की छवि दृश्य में शायद शून्य आकार का आयताकार होगा, क्योंकि आपने इसमें कोई तस्वीर नहीं डाली है। तो स्पिनर अंदर है लेकिन अदृश्य है।

बजाय imageView भीतर स्पिनर डालने की, बस इसे कोशिका के भीतर डाल दिया ...

[cell addSubview:spinner]; 
spinner.frame = CGRectMake(145, 0, 30, 30); // if you want it centered horizontally... 

आप भी

cell.accessoryView = spinner; 

कर सकता है के लिए बिल्कुल दाईं स्पिनर से अधिक डाल करने के लिए सेल का

+0

AcessoryView बहुत अच्छी तरह से काम किया ... लेकिन स्पिनर.फ्रेम नहीं है ... मुझे एक समाधान मिला जो "सफेद वर्ग" UIImage बनाने के लिए है और उन्हें cell.imageView.image के रूप में रखा गया है ... उन्हें स्पिनर दिखाई देता है ... लेकिन आपकी मदद के लिए धन्यवाद ..! – Thiago

+0

इसके बारे में खेद है; मुझे अन्य टिप्पणीकार पर भरोसा करने के बजाय खुद का परीक्षण करना चाहिए था! –

9

मैं इस सवाल का जवाब मिल गया ...

डेविड Maymudes था आंशिक रूप से सही है ... यह है आवश्यक cell.imageView करने के लिए एक "पृष्ठभूमि" के लिए ... लेकिन होना चाहिए एक छवि ही नहीं, एक फ्रेम। तो बस एक "सफेद पृष्ठभूमि" के रूप में एक UIImage बनाएँ और cell.imageView.image में सेट करें। कोड होगा:

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] 
     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
UIImage *whiteback = [[UIImage alloc] initWithContentsOfFile:@"whiteback.png"]; 
cell.imageView.image = whiteback; 
[cell.imageView addSubview:spinner]; 
[spinner startAnimating]; 
[email protected]"Carregando..."; 
[whiteback release]; 
[spinner release]; 

whiteback.png सिर्फ एक 25x25 पिक्सल सफेद वर्ग है ...

सभी को धन्यवाद के लिए मदद ... आप देखें ...

9

की एक मामूली संशोधन थियागो से विधि:

मैं सेल को देखने के लिए सीधे स्पिनर जोड़ने एक छोटे से hacky महसूस किया, तो मैं छवि दृश्य के रूप में एक 1x1 पारदर्शी PNG का इस्तेमाल किया और यह आकृति परिवर्तन होने के लिए जो कुछ भी मेरे स्पिनर आकार है लगता है:

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"NoReuse"] autorelease]; 
cell.textLabel.text = @"Loading..."; 

UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] 
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease]; 

// Spacer is a 1x1 transparent png 
UIImage *spacer = [UIImage imageNamed:@"spacer"]; 

UIGraphicsBeginImageContext(spinner.frame.size); 

[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)]; 
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 
cell.imageView.image = resizedSpacer; 
[cell.imageView addSubview:spinner]; 
[spinner startAnimating]; 

return cell; 

एक सेल है कि इस तरह दिखता है देता है कि:

loading cell

+0

एक आकर्षण की तरह काम करता है :-) – crosscode