2014-04-25 10 views
6

मुझे इस तरह की समस्या है:अलर्ट व्यू को कस्टम दृश्य जोड़ने

मैं एक अलर्ट व्यू के अंदर एक अनुकूलित दृश्य दिखाना चाहता हूं। इसलिए मैं एक अलग xib फ़ाइल बनाता हूं और अपना इंटरफ़ेस डिज़ाइन करता हूं। और इसके लिए क्लास भी कार्यान्वित करता हूं। लेकिन जब मैं नीचे कोड लागू करता हूं, तो यह मुझे एक त्रुटि देता है।

इस

कोड है:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm your Action" 
                message:@"Click OK to confirm" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:@"Cancel",nil]; 


    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"customDialogViewController" owner:self options:nil]; 
    customDialogViewController *myView = (customDialogViewController*) [subviewArray objectAtIndex:0]; 

    [alert setValue:myView forKey:@"accessoryView"]; 
    //alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    alert.tag = KAlertViewthree; 
    [alert show]; 

और यह मेरा त्रुटि है:

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<ScheduleView: 0x8adf1a0> should have parent view controller:<_UIModalItemAccessoryViewControllerForLegacyAlert: 0xa888b70> but actual parent is:<UINavigationController: 0x8add8c0>' 

मैं सच में आईओएस के लिए नए मैं इस गलत करते हैं development.did? गलती कहां है? मुझे नहीं पता कि यह निब फ़ाइल यहां क्या बात कर रही है "loadNibNamed: @bla boa" मैंने अभी इसके लिए अपना xib नाम दिया है। क्या कोई मुझे ऐसा करने का बेहतर तरीका दे सकता है या क्या आप मुझे बता सकते हैं कि मुझे इस मुद्दे को ठीक करने के लिए कहां बदलना है?

कृपया मुझे कुछ गाइड करें .. धन्यवाद।

+1

, कल मैं पहले से ही आप मेरा उत्तर में बताया है कि इसके UIAlertView.In की नहीं एक समस्या अपने कंसोल लॉग ऑन इसकी स्पष्ट रूप से उल्लेख में अपने viewcontroller.So बदलने अपने प्रश्न इसकी नहीं एक कुछ मुद्दा है कि वहाँ UIAlertView की समस्या। – Jayaprada

+0

महोदय, मैंने कल जो कहा है उसका पालन किया है। लेकिन काम नहीं किया। इसलिए मैं इस https://github.com/wimagguc/ios-custom-alertview का पालन करता हूं। किसी भी तरह से मैं अलर्ट कस्टम दृश्य में स्टार अंक जोड़ने में सक्षम हूं। लेकिन आप एक और टेक्स्ट फ़ील्ड और लाइबल्स नहीं जोड़ सकते हैं, क्या आप मुझे एक तरीका बता सकते हैं – Darshana

+0

मैंने इसे github पर बनाया है। इसे डाउनलोड करें और मुझे UIAlertView पर अपनी समस्या के बारे में बताएं। https://github.com/jayaprada-behera/CustomAlertView। लेकिन ऊपर उल्लिखित मुद्दा UIAlertView – Jayaprada

उत्तर

3
सभी जो इस समस्या होने के लिए

, मैं स्टार के निशान के लिए this link..and का पालन किया है, मैं this इस्तेमाल किया ..

तुम सब करने की है नीचे जोड़ने है परियोजना के लिए फ़ाइलों को

  • CustomIOS7AlertView.h
  • CustomIOS7AlertView.m
  • JSFavStarControl.h
  • JSFavStarControl.m

और कोड नीचे डाल जहां चेतावनी दृश्य

// Here we need to pass a full frame 
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init]; 

// Add some custom content to the alert view 
[alertView setContainerView:[self createDemoView]]; 

// Modify the parameters 
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Close1", @"Close2", @"Close3", nil]]; 
[alertView setDelegate:self]; 

// You may use a Block, rather than a delegate. 
[alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) { 
    NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]); 
    [alertView close]; 
}]; 

[alertView setUseMotionEffects:true]; 

// And launch the dialog 
[alertView show]; 

पॉप अप करना चाहते हैं और createDemoView की विधि के अंदर, आप अपने को लागू करने के लिए है अनुकूलित दृश्य।मेरे मामले में यह इस तरह है

UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 100)]; 

//alertView.tag=2; 

UILabel *rateLbl=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 45)]; 
rateLbl.backgroundColor=[UIColor clearColor]; 
rateLbl.font=[UIFont boldSystemFontOfSize:15]; 
[email protected]"Rate"; 

UILabel *cmntLable=[[UILabel alloc]initWithFrame:CGRectMake(10, 45, 290, 45)]; 
cmntLable.backgroundColor=[UIColor clearColor]; 
cmntLable.font=[UIFont boldSystemFontOfSize:15]; 
[email protected]"Add Comment"; 

UIImage *dot, *star; 
dot = [UIImage imageNamed:@"dot.png"]; 
star = [UIImage imageNamed:@"star.png"]; 
JSFavStarControl *rating = [[JSFavStarControl alloc] initWithLocation:CGPointMake(150, 20) dotImage:dot starImage:star]; 
[rating addTarget:self action:@selector(updateRating:) forControlEvents:UIControlEventValueChanged]; 


UILabel *lblAlertTItle=[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 290, 45)]; 
lblAlertTItle.backgroundColor=[UIColor clearColor]; 
lblAlertTItle.textAlignment=UITextAlignmentCenter; 
lblAlertTItle.font=[UIFont boldSystemFontOfSize:18]; 
[email protected]"Choose your sharing option"; 


UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(150, 57, 100, 25)]; 
text.backgroundColor=[UIColor whiteColor]; 
//[demoView addSubview:lblAlertTItle]; 
[demoView addSubview:text]; 
[demoView addSubview:rating]; 
[demoView addSubview:rateLbl]; 
[demoView addSubview:cmntLable]; 


return demoView; 

तो मेरा आउटपुट इस तरह है। इसका उपयोग करें और मज़े करें :)

मेरी मदद करने वाले सभी लोगों के लिए धन्यवाद।

enter image description here

3

ios7 में देशी Alert-view में alert-view के उप-दृश्य के रूप में कस्टम व्यू जोड़ने के लिए संभव नहीं है। आप इस तरह के कार्य करने के लिए ios-custom-alertview का उपयोग कर सकते हैं जो आप चाहते हैं कि कर सकते हैं। आशा है कि यह आपके लिए सहायक होगा।

मैं इस प्रोजेक्ट में दो बोले फ़ाइल जोड़ने के साथ इस ios-custom-alertview का उपयोग कर रहा हूं।

CustomIOS7AlertView.h 
CustomIOS7AlertView.m 

और कैसे उपयोग करने के लिए नहीं है quick-start-guide

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