iphone add view controller as subview - iphone

I would like to show a modal view but don't want to use the standard methods because they don't let me animate the subview as I like.
I tried the fowlloing code:
EventsCalendarController *calController = [[EventsCalendarController alloc] init];
calController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:calController animated:YES];
[calController release];
but the problem is that I would like to show it using some animation, so I am using the following code along with [UIView beginAnimation] etc...
EventsCalendarController *calController = [[EventsCalendarController alloc] init];
calController.modalPresentationStyle = UIModalPresentationFormSheet;
[self.view addSubview:calController.view];
[calController release];
The problem is that whenever I call the following code from the 'EventsCalendarController' I get an exception:
- (IBAction)btnClose_TouchUpInside:(id)sender {
[self.view removeFromSuperview];
}
here is the exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType btnClose_TouchUpInside:]: unrecognized selector sent to instance 0x7029d60'
How can I solve/overcome this problem? Thank you.
UPDATE:
Solved: I found the following code on GitHub: https://github.com/horaceho/iphone-custom-dialogbox
It is a complete example with very few code to write. I did not find the original author, so I am just linking to the code...

Are you trying to remove the calendar view which you have added as a subview ? if so then
the code must be like this :
[calController removeFromSuperview];

Related

App crashes and Program receives error signal SIGABRT

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: [LeavesCache setDataSource:]: unrecognized selector sent to instance 0x7db1f30
Added Exception breakpoint and found that problem is at this line
pageCache = [[LeavesCache alloc] initWithPageSize:self.bounds.size];
- (void) initialize {
backgroundRendering = NO;
pageCache = [[LeavesCache alloc] initWithPageSize:self.bounds.size];
}
- (id) initWithPageSize:(CGSize)aPageSize
{
if (self = [super init]) {
pageSize = aPageSize;
pageCache = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void) setDataSource:(id<LeavesViewDataSource>)value {
pageCache.dataSource = value;
}
Have no idea how to fix this if some one can help me in this
I'm assuming you're using [this library][1], but it doesn't match up with what you've posted. Because the LeavesCache library on GitHub has no setDataSource method in the code - it's property declared instead. Have you made modifications to the source? Somebody has, because you seem to be setting the pageCache instance variable in one method to a NSMutableDictionary, and in another to a LeavesCache object.
Is there any particular reason why you're using this library? As far as I can tell, it hasn't been updated for three years, and iOS has supported iBooks like page turning interface since iOS 5 natively, using the UIPageViewController class.

PDF ScrollView not scrolling

My PDF scroll view (copied from Apple’s ZoomingPDFViewer example, but modified a bit) can’t seem to zoom, although it’s displaying the data.
Here is what Apple uses in the example to add it:
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
[(PDFScrollView *)self.view setPDFPage:PDFPage];
And because that second line gave me errors, I changed it to this:
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:self.view.frame];
[sv setPDFPage:PDFPage];
self.view = sv;
But now I can’t seem to zoom the PDF.
The Apple one works well without errors, but if I use this line in my app, I get the following error when that view loads:
-[UIView setPDFPage:]: unrecognized selector sent to instance 0x1c5b10b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setPDFPage:]: unrecognized selector sent to instance 0x1c5b10b0'
*** First throw call stack:
(0x3424c2a3 0x33a1e97f 0x3424fe07 0x3424e531 0x341a5f68 0x8c499 0x36da3595 0x36df813b 0x36df8081 0x36df7f65 0x36df7e89 0x36df75c9 0x36df74b1 0x36de5b93 0x36de5833 0x79acd 0x36e46275 0x36ec8ea9 0x39249a6f 0x342215df 0x34221291 0x3421ff01 0x34192ebd 0x34192d49 0x34efb2eb 0x36dd8301 0x6e601 0x38e17b20)
libc++abi.dylib: terminate called throwing an exception
The only other difference in my setup is that the view controller where this is called is inside a navigation controller, which is inside of a tab bar controller. But I can’t see how this would affect the problem.
Any tips?
[UPDATE]
This is my custom init method:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.decelerationRate = UIScrollViewDecelerationRateFast;
self.delegate = self;
self.scrollEnabled = true;
}
return self;
}
It is the same as initWithCoder except that I added self.scrollEnabled = true;.
I also tried these, and it still didn’t work:
//UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.frame];
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:self.view.frame];
self.view = sv;
[(PDFScrollView *)self.view setPDFPage:PDFPage];
When I use the commented-out line (UIScrollView), it gives me the same error, except that it says [UIScrollView setPDFPage:]: unrecognized.... When I use the uncommented line (PDFScrollView), it gives me no error and shows the PDF, but there’s still no zooming.
self.view must be a scroll view in order to be cast as a PDFScrollView and accept its methods. By default, self.view is a UIView. Either change the view to a scroll view in your XIB file (delete the view and link the scroll view to view in File's Owner) or do it programmatically.

Which class must I extend?

(I am developing an app that presents chat messages in a table. But, this chat can't be started by the user, when the user receives a message the chat view opens. So, I made this code:
- (void) newMessageReceived:(NSMutableDictionary *)message
{
General *general = [General sharedManager];
NSString *firstmessage=[message objectForKey:#"msg"];
NSString *from=[message objectForKey:#"sender"];
NSArray *listItems = [from componentsSeparatedByString:#"#"];
NSString *fromsplit=[listItems objectAtIndex:0];
general.firstmess=firstmessage;
general.firstfrom=fromsplit;
NSLog(#"Mensaje recibido: %# de %#", [message objectForKey:#"msg"], fromsplit);
ChatViewController *cvc=[[ChatViewController alloc]initWithNibName:#"Chat" bundle:nil];
[[self navigationController]pushViewController:cvc animated:YES];
}
Everything is ok, until here. The ChatViewController extends UITableViewController. But, when a message is received i get the following exception:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "Chat" nib but didn't get a UITableView.
Then, i try to change the class extended to UIViewController (did this to check that the program enters the numberOfRowsInSection method) and then i receive:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatViewController setTableViewStyle:]: unrecognized selector sent to instance 0x9863200'
I think that solving the first exception would fix my problem. Any help?
Thank you.
In the second exception i think you have called [self setTableViewStyle:] method, while
you have made it UIViewController.
So try to call this method by tableViewOutlet.
[tableView setTableViewStyle:];
Hope this will help you
Solved it. i click the .xib file, under "objects", clicked "View". And then, in the Identity Inspector (the third one, starting from the left), in Custom Class, set it to UITableView. It was simply "View" before. And then, everything worked fine.

App Crashing when returning from background

My application is crashing when it returns back from the background at certain places:
-[UITableViewCellContentView updateToInterfaceOrientation]: unrecognized selector sent to instance 0x165470
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView updateToInterfaceOrientation]: unrecognized selector sent to instance 0x165470'
The error is always similiar somtimes its with
[UIScrollViewDelayedTouchesBeganGestureRecognizer updateToInterfaceOrientation]
I'm really clueless as to why this is happening, any help would be much appreciated.
EDIT:
Ok, this is how I am creating my table view in the loadView method:
int tableCells = [formDS.tableItems count];
int tableHeight = FORM_TABLE_CELL_HEIGHT * (tableCells);
UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, yCoord, FORM_TABLE_WIDTH, tableHeight) style:UITableViewStyleGrouped];
[table setBackgroundView:nil];
table.backgroundView.backgroundColor = UIColorFromRGB(FORM_BODY_COLOR);
table.backgroundColor = UIColorFromRGB(FORM_BODY_COLOR);
table.dataSource = self;
table.delegate = self;
[localContainerView addSubview:table];
It looks like you have some released object and because of that some other objects now present at the same address in memory receive the call for updateToInterfaceOrientation.
Try hitting COMMAND + SHIFT + B (or go to Product -> Analyze in XCode's top bar menu) to have XCode make a static analyze of your code and get some hints of what might go wrong.
Hope that's going to help!

dismissModalViewControllerAnimated makes my app crash :(

I'm creating an iPad app, and I have two classes: NWRootViewController : UITableViewController and UINewFeedViewController : UIViewController. In NWRootViewController I have an UIBarButtonItem, which, when tapped, pops up a modal view controller called NWNewFeedViewController:
// THIS CODE IS IN NWROOTVIEWCONTROLLER.M
// New Feed
-(IBAction)showNewFeedViewAction:(id)sender {
[newFeedViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentModalViewController:newFeedViewController animated:YES];
}
This works fine. However, in the NWNewFeedViewController's view, I have another UIBarButtonItem which does this when tapped:
// THIS CODE IS IN NWNEWFEEDCONTROLLER.M
// Buttons
-(IBAction)cancelAction:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
When I tap this button, the app crashes with:
2010-04-10 12:39:46.703 News[580:207] *** -[NWDetailViewController cancelAction:]: unrecognized selector sent to instance 0x4741110
2010-04-10 12:39:46.705 News[580:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NWDetailViewController cancelAction:]: unrecognized selector sent to instance 0x4741110'
2010-04-10 12:39:46.705 News[580:207] Stack: (
40878667,
2458187017,
41150267,
40613142,
40609810,
2776006,
4876265,
2776006,
3246293,
3255055,
3250242,
2899304,
2793965,
2825287,
49238396,
40419388,
40415304,
49232029,
49232226,
2817505
)
Can anyone help me? Thanks
Your cancel button has a target of your detail controller; you meant to target your new feed controller. So check how you configured the cancel button.
Your app is trying to call an object that has already been released. Enable zombie objects as explained here to find out what object is trying to be accessed.