Link ActionSheet button to TableView - ios

I have an action sheet that pops up on a view controller. That action sheet has 3 buttons, "Choose Existing Icon", "Take Picture", and Cancel.
I have the Take Picture button working just fine. However, I want the Choose Existing Icon button to link to a UITableViewController that has a list of premade icons that I will have seeded the application with. How do I go about linking the button to the table of icons?
I have tried this in the clickedAtButtonIndex method,
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:#"Choose Existing Icon"])
{
IconViewController *iconPicker = [[IconViewController alloc] init];
[self presentViewController:iconPicker animated:YES completion:nil];
}
But this crashes. I want it to let the user see a table of icons and select one. Then have that icon show up in a UIImageView on the original controller.
Thanks for any help
EDIT
I'll change to buttonIndex, thanks for the tip on that. I followed a tutorial and didn't think much about it.
When I run the code as it is here, I get this error when I tap the "Choose Existing Icon" button.
2013-10-01 13:06:18.680 CardMinder[594:60b] * Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit/UIKit-2903.2/UITableView.m:6235
2013-10-01 13:06:18.684 CardMinder[594:60b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

There is a method for calling functions at button touchs in uiactionsheet similar to uialertview
http://blog.mugunthkumar.com/coding/ios-code-block-based-uialertview-and-uiactionsheet/ ..... read this blog

Related

UIActionSheet _button valueforKey Crash in iOS8

In iOS 8 , following codes crash that add image to UIActionSheet's _button valueForKey.
UIActionSheet *action = [[UIActionSheet alloc ] initWithTitle:#"Choose Action!" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Start Auto Scroll", nil];
[[[action valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"autoScroll.png"] forState:UIControlStateNormal];
[action showInView:self.view];
Crash Log is
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIActionSheet 0x7ff6d8c61030> valueForUndefinedKey:]: this class is not key value coding-compliant for the key _buttons.'
How can i solve it?
What you are doing was never legal. You cannot modify an action sheet's interface directly. If your code was ever getting past the App Store Guardians, that was just an oversight.
Use a custom presentation transition animation to make a view controller view that looks like an action sheet (or, indeed, one that doesn't look like an action sheet). Making a presented view controller view that partially covers the screen is easy and legal in iOS 7 and 8.

Access all UIAlertView object as a global object to control it Universally(to resolve CRASH in alert after deallocating the view contoller)

My requirement is to make my app's third tab as the home screen,and also whenever the user moves the app in background and while again moving the app to foreground it should be the home screen as our third tab instead the app is in any of the places in the app.
This issue is handled(making third tab as home screen instead the app is in any of the places/scenarios in the app).,But i have an issue now which is generated by this resolution.
Problem :- If any alert is displaying in any view and we are making the app background-foreground ,the app comes to the third tab from that screen,and the alert is still there and if we click on the alert button ,then as per the rules of IOS the "self" object of the screen of alert is deallocated(because now we are in the home screen and the alert is here) and app CRASHES !
Tried some resolutions :-
1.In a screen ,I made an global object of UIAlertView and using below line of code in applicationDidBecomeActive method of the Screen...
[_alertToRemoveContact dismissWithClickedButtonIndex:1 animated:NO];
This is working code for this view,but my problem with resolution is that i need to create a global object of alert view in all places of the app which is a very much time consuming task because i am using around 250 alerts in the project.
2.I am killing the app whenever it moves to background ,In this resolution the problem is that my app will not work its downloading functionality in background cause the app is killed.
Need help for the resolution of this issue if any one need more explanations,please leave comments.
My Crash Log....
* -[ContactShowViewController respondsToSelector:]: message sent to deallocated instance 0x1138c4e0*
*Where ContactShowViewController will differ a/c to the screen
Thanks in advance !!!
Let's try singleton:
__strong static AlertUtil* _sharedInstance = nil;
#implementation AlertUtil
{
UIAlertView *alertView;
}
+ (AlertUtil *)sharedInstance
{
#synchronized(self)
{
if (nil == _sharedInstance)
{
_sharedInstance = [[AlertUtil alloc] init];
}
}
return _sharedInstance;
}
- (void)showConfirmAlertWithMessage:(NSString *)msg cancelBtnTitle:(NSString *)btn1 okbtnTitle:(NSString *)btn2 delegate:(id)delegate tag:(int)tag
{
alertView = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:delegate cancelButtonTitle:btn1 otherButtonTitles:btn2, nil];
alertView.tag = tag;
[alertView show];
}
- (void)cancel
{
if (alertView){
[alertView dismissWithClickedButtonIndex:0 animated:NO];
}
}
I have resolved this issue with the help of below solution :-
1.I created an app delegate instance of UIAlertView.
2.I implemented an alert view delegate method "will present alert view...",this method gives me all the alert view objects as a parameter where i have assigned it to my app delegate object of alert view.
3.On application life cycle method "applicationDidEnterBackground" i am using below code ...,which resigns my alert dailog on coming from background to foreground...
if ([AppDelegate shared].alertObserver)
{
//Dismissing alert which was shown before moving to background
[[AppDelegate shared].alertObserver dismissWithClickedButtonIndex:0 animated:NO];
[AppDelegate shared].alertObserver=nil;
}

Embedded Table View in UIView container

So here's the case:
I wish to fill the prototype cells with the names of the friends selected in the UIPickerView over there. I have programatically filled the picker with the correct data, and set its properties using the delegate functions.
The "New Game Friends View" you see here has its own viewcontroller subclass, as has the table view, which I attempt to embed into a UIView on the "New Game Friends View".
I have in many ways tried to add data to the prototype cells, but with no luck. Here's my current addBtnClicked function:
- (IBAction)addBtnClicked:(id)sender {
WHGFriendTableViewController* tabView = (WHGFriendTableViewController*) [[self childViewControllers] objectAtIndex:0];
NSInteger row = [friendPicker selectedRowInComponent:0];
[[tabView selectedFriends] addObject:[[self friendList] objectAtIndex:row]];
}
This pretty much crashes my app. Whenever I hit the Add Friend button, the iPhone sends an abort signal, and gives back this message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController
selectedFriends]: unrecognized selector sent to instance 0x978d530'
Any help with this problem is very appreciated. Thanks in advance!
Do you have a property called selectedFriends on your New Friends view controller?
If the answer is yes try:
- (IBAction)addBtnClicked:(id)sender {
WHGFriendTableViewController* tabView = (WHGFriendTableViewController*) [[self childViewControllers] objectAtIndex:0];
NSInteger row = [friendPicker selectedRowInComponent:0];
[[self selectedFriends] addObject:[[self friendList] objectAtIndex:row]];
}
If selectedFriends is a property of WHGFriendTableViewController, you should create a public method that adds a friend to the Mutable Array and call it from addBtnClicked IBAction.

NSConcreteMapTable backdropView:willChangeToGraphicsQuality: ...error

I'm developing an iPad app to help me to manage my expenses when I'm abroad.
I have a split view with the classical master and detail views. In the master there is the list of the expenses and in the detail view, guess what? The details of every expense!
When I tap on a button in the detail a new view is loaded using a modal segue with a Form Sheet. The user insert a number and if that number is bigger than a certain value the colors of the labels in the master and in the detail will change.
When I save this number I dismiss the modal view and send a NSMessage to the master in order to reload the table with the new label colors and reload the detail view selected previously.
Everything work using the iOS Simulator, but when I run the app on my iPad (iPad 2), everything freeze and I got this message:
2013-11-09 21:52:04.763 IOUinTravel[562:60b] -[NSConcreteMapTable
backdropView:willChangeToGraphicsQuality:]: unrecognized selector sent
to instance 0x18b8fb00 2013-11-09 21:52:04.767 IOUinTravel[562:60b]
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMapTable
backdropView:willChangeToGraphicsQuality:]: unrecognized selector sent
to instance 0x18b8fb00'
* First throw call stack: (0x2df5bf4b 0x387386af 0x2df5f8e7 0x2df5e1cb 0x2dead4d8 0x30c88b43 0x306cd7b5 0x306cd6e5 0x306cd7d5
0x306cd6e5 0x306da5c3 0x306da417 0x30785f67 0x30785d83 0x3077de85
0x3077d30d 0x3077d07d 0x3077d015 0x306ceda3 0x30355c6b 0x3035147b
0x3035130d 0x30350d1f 0x30350b2f 0x306c70c3 0x2df271cd 0x2df24b71
0x2df24eb3 0x2de8fc27 0x2de8fa0b 0x32b70283 0x30733049 0x9a3d5
0x38c40ab7) libc++abi.dylib: terminating with uncaught exception of
type NSException (lldb)
I really do not know why and how to solve it.
The methods I've used are:
In the Form Sheet modal view:
- (IBAction)saveNumber:(id)sender {
// Do some stuff here
[self dismissViewControllerAnimated:YES completion:^{ [[NSNotificationCenter defaultCenter] postNotificationName:#"reloadAfterExpenseCheck" object:self];}];
}
In the main view:
- (void)reloadAfterExpenseCheck:(NSNotification *)notification
{
if ([[notification name] isEqualToString:#"reloadAfterExpenseCheck"]) {
NSLog(#"Messaggio ricevuto!");
NSLog(#"%#", self.indexPathToUpdate);
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:self.indexPathToUpdate animated:NO scrollPosition:UITableViewScrollPositionNone];
[self performSegueWithIdentifier:#"detailExpense" sender:self];
}
}
The segue #"detailExpense" works when I trigger it selecting a cell in the master table, so I do not know where is the problem... in the iOS sim it works!
Thank you for your answers.
I've solved this problem, I do not know it it is the best way but it works now.
I started to think that maybe there could be some asynchronous task going on. My Mac Mini cpu was fast enough to complete the first task, load the view and fill it with my data, the iPad cpu maybe was too slow so the view wasn't loaded... at least that is my guess.
I've simple added a NSTimer that fires the method used to load the detail view after a short time. The user do not notice the delay but it gives time to the iPad.
That's the code:
- (void)reloadAfterExpenseCheck:(NSNotification *)notification {
if ([[notification name] isEqualToString:#"reloadAfterExpenseCheck"]) {
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:self.indexPathToUpdate animated:NO scrollPosition:UITableViewScrollPositionNone];
//[self performSegueWithIdentifier:#"detailExpense" sender:self];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(loadIt) userInfo:nil repeats:NO];
}
}
-(void)loadIt
{
[self performSegueWithIdentifier:#"detailExpense" sender:self];
}

unrecognized selector sent to instance

I am trying to get a pop up menu on iPhone.
The main app is using storyboard, but the pop up is a separate xib file that I load:
menu = [[UIViewController alloc] initWithNibName:#"SimpleMenuController" bundle:nil];
[self.view addSubview:menu.view];
and I slide it in and out with animation when pressing a button.
that works fine, but I get a problem when I try to press a button inside that pop up menu
I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UIViewController PressCategory:]:
unrecognized selector sent to instance 0x8d3c040'
I have connected the button to PressCategory function
I have connected the view to the file owner.
What I have noticed is that my ViewController is called SimpleMenuViewController, that is where the PressCategory function is, so of course it will not find the selector. But I don't know what I am doing wrong in connecting in the xib file.
Change your code to:
menu = [[SimpleMenuViewController alloc] initWithNibName:#"SimpleMenuController" bundle:nil];
so that you're instantiating the correct class.
Do you have PressCategory function in your SimpleMenuViewController?
If yes, then check weather its parameterized or not.
Declare function in .h file like this:
-(IBAction)PressCategory:(UIButton *)sender;
Define it in .m file like this:
-(IBAction)PressCategory:(UIButton *)sender {
// write your code here
}

Resources