I am having some hard time with TableView insite UIPopover, the table is simply empty, even though it is a static table view.
code:
- (IBAction)settingsBtnPressed:(id)sender {
if(self.pop.isPopoverVisible) {
[self.pop dismissPopoverAnimated:YES];
} else {
//SettingsViewController *s = [[SettingsViewController alloc] init];
SettingsViewController *s = [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
s.brain = self.brain;
self.pop = [[UIPopoverController alloc] initWithContentViewController:s];
[self.pop setPopoverContentSize:CGSizeMake(400, 500)];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
Attaching screenshots:
Have you implemented methods like cellForRow:atIndex:, numberOfSections:inTableView: and numberOfRows:inSection ?
Maybe you are not using UITableViewController but rather UIViewController in your header file.
Related
I would like to present a popover from UIBarButtonItem present in UITabBarController using objectiveC in iOS9. This popover is a UITableViewController. I have coded it in the following way
- (IBAction)MenuButtonPopOverTouch:(id)sender {
LogoutTableViewController* content = [[LogoutTableViewController alloc] init];
content.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:content animated:YES completion:nil];
UIPopoverPresentationController *PopOverPresentation = [content popoverPresentationController];
PopOverPresentation.permittedArrowDirections = UIPopoverArrowDirectionDown;
}
I think i have missed the content size of the popover but don't know how to initialize it. Any help is appreciated. Attaching a preview of my storyboard if needed anything else please let me know
I found answer to my question here is the solution
- (IBAction)MenuPopOver:(id)sender {
[self performSegueWithIdentifier:#"CustomerMenu" sender:self.MenuBarButtonItem];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString *popoverIdentifier = segue.identifier;
if([popoverIdentifier isEqualToString:#"CustomerMenu"]){
UIViewController *dvc = segue.destinationViewController;
dvc.preferredContentSize = CGSizeMake(150, 50);
UIPopoverPresentationController *ppc = dvc.popoverPresentationController;
if (ppc) {
ppc.delegate = self;
}
}
}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
return UIModalPresentationNone;
}
I found it through this link PopoverPresentationController
It has been tested as well
I am trying to use an MGSplitViewController, but rather than having it set as the rootViewController, I want it to show modally. This is the code I am using so far
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
if(splitViewController == nil)
{
self.splitViewController = [[MGSplitViewController alloc] init];
self.rootViewController = [[RootViewController alloc] init];
self.detailViewController = [[DetailViewController alloc] init];
}
[splitViewController setViewControllers:[NSArray arrayWithObjects:rootViewController, detailViewController, nil]];
if (NO) { // whether to allow dragging the divider to move the split.
splitViewController.splitWidth = 15.0; // make it wide enough to actually drag!
splitViewController.allowsDraggingDivider = YES;
}
splitViewController.delegate = detailViewController;
[rootViewController performSelector:#selector(selectFirstRow) withObject:nil afterDelay:0];
[detailViewController performSelector:#selector(configureView) withObject:nil afterDelay:0];
[self presentViewController:splitViewController animated:YES completion:nil];
}
This works almost fine, but the buttons in the detailViewController do not work. They do nothing. Also, when I click a button in the left panel, the text doesn't change in the detailViewController as it does in the same project.
Am I missing something?
I'm also working with MGSplitViewController, but it sounds to me like you need to set up some communication between your master and detail views. If you look at the demo project, you can see they use delegates to that effect.
I'm still new to iOS development but I've ran into a problem that I can't solve and I've tried looking online but can't find anything yet.
I'm using a UIImagePickerController to pick and image and I'm using it in the App Delegate. When an image is returned, in the imagePickerController:didFinishPickingMediaWithInfo method, I want to make a new navigation controller with a view controller and put it over the "app".
Here is how I'm doing it:
CustomNavigationController *customNavigationController = [[CustomNavigationController alloc] init];
PhotoViewController *photoViewController = [[PhotoViewController alloc] initWithNibName:#"PhotoViewController" bundle:[NSBundle mainBundle]];
[customNavigationController pushViewController:photoViewController animated:NO];
[customNavigationController.view setFrame:[[UIScreen mainScreen] applicationFrame]];
[photoViewController release];
[self.window addSubview:customNavigationController.view];
//Call method of photoViewController.
[[customNavigationController.viewControllers objectAtIndex:0] addPhotoFromData:info];
[self.tabBarController dismissViewControllerAnimated:YES completion:nil]; //Get rid of UIImagePickerController
However in the photoViewController, I don't have access to any instance variables synthesized and loaded in viewDidLoad. They all return to null. There is also a tableView and calls to reload the tableView do not actually cause the tableView to respond.
Here is some of the code from photoViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.photoCount = 0;
self.timestamp = [[NSDate date] timeIntervalSince1970];
self.photos = [[NSMutableArray alloc] initWithCapacity:5];
self.photosData = [[NSMutableArray alloc] initWithCapacity:5];
self.uploadingCount = 0;
UINib *customCell = [UINib nibWithNibName:#"CustomTableCell" bundle:[NSBundle mainBundle]];
[self.tableView registerNib:customCell forCellReuseIdentifier:#"customCell"];
self.tableView.separatorColor = [UIColor clearColor];
NSLog(#"%#", self);
}
and also the addPhotoFromData method:
- (void)addPhotoFromData:(NSDictionary *)info
{
[self.photos addObject:info];
NSLog(#"%#", self.photos); //Doesn't add "info" and does not return anything when later called from other methods.
[self.tableView reloadData]; //Doesn't work
Everything was working before I add in the UINavigationController. I'm completely lost.
EDIT: After some more debugging attempts, I have discovered that the view is not loaded when addPhotoFromData is called. viewDidLoad is called afterwords. Is there a way to delay method calls?
Any reason you can't have the PhotoViewController call addPhotoFromData: inside the viewDidLoad method? You can always access properties of the app delegate from the view controller:
YourAppDelegateType * delegate = [UIApplication sharedApplication].delegate;
[self addPhotoFromData:delegate.info];
sorry for my bad english, if you don't understand me, please ask! :)
I have a problem with Objective-C.
I try to explain my problem as easy as possible:
I made two interfaces 'profile' and 'editProfile' in 'profile.m".
I'd like to have a table (or for the beginning a *label) in profile, then I can click at 'edit' and fill in a TextField a string. With a 'save' button i save this string in a database (or an extern variable). Thats no problem, of course..
Now my problem: With clicking on 'save' i want to get back to the 'profile' page, my code:
[self.navigationController popViewControllerAnimated:YES];
But I want to have the IBOutlet UILabel *label (or table) updated. This *label should show the text, which I entered in the TextField in 'editprofile'.
But it doesn't update! Parts of my code 'profile':
#implementation Profil
#synthesize label;
// ....
-(void) method{
Database* db = [[Database alloc] init];
if([db getadresse]!=nil){
NSString *s=[db getadresse];
label.text=s;
[data addObject:s];
[datadetail addObject:#"Adresse"];}
//...
and 'editprofil':
-(IBAction)save:(id)sender{
Database* db = [[Database alloc] init];
[db setadresse:TextField.text];
[self.navigationController popViewControllerAnimated:YES];
Profile* p= [[Profile alloc] init];
[p method];}
What can I do to get *label updated immediately?
Thanks!
And what about a table in 'profile'? I want to get it refreshed.
I put the following lines in 'ViewWillApear':
data = [[NSMutableArray alloc] init]; //NSMutableArrays
datadetail = [[NSMutableArray alloc] init];
database* db = [[database alloc] init];
if([db getadresse]!=nil){
NSString *s=[db getadresse];
[data addObject:s];
[datadetail addObject:#"Adresse"];}
if([data count]>0){
UITableView *table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]
style:UITableViewStylePlain];
table.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
table.delegate = self;
table.dataSource = self;
[table reloadData];
self.view = table;
}
So the table (created in ViewWillAppear) should show the one entry of the Array ('[db.getadresse]'). But i get the Exception:
-[Profile tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x688d290
NumberOfRowsInSection is just: return [data count]
Can u tell me what goes wrong?
Thank you!
UIKit will sends the viewWillAppear: message to a view controller when its view appears. Your first ("profile") view controller can update the label when it receives that message:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.label.text = code to get the text from the database;
}
Hi In my app I have a button so when you click it a UIPopover comes up with an add contact view in it. It all workers except when you press save. It doesn't Dismiss.
-(IBAction) addcontact
{
ABNewPersonViewController *contacts = [[ABNewPersonViewController alloc] init];
// imagePicker.delegate = self;
// UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:contacts];
UINavigationController *addContactNavController = [[UINavigationController alloc] initWithRootViewController:contacts];
popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
popover.popoverContentSize = CGSizeMake(320, 1000);
[popover presentPopoverFromRect:CGRectMake(935, 270, 175, 300)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
[popover retain];
[addContactNavController release];
[contacts release];
}
Implement the ABNewPersonViewControllerDelegate protocol and assign the delegate in your method above –
contacts.newPersonViewDelegate = self;
You can then dismiss the popover in the delegate function –
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView
didCompleteWithNewPerson:(ABRecordRef)person {
[popOver dismissPopoverAnimated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[popOver release];
}
well,
[self dismissModalViewControllerAnimated:YES];
respecively
[popover dismissPopoverAnimated:YES];
should do it?
Edit: to be more concrete:
....
popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
addContactNavController.delegate = self;
now on saving, do something like:
-(IBAction) saveStuff {
... saving...
[delegate closePopup];
}
and in your File with -(IBAction) addcontact you do:
-(void) closePopup {
[self dismissModalViewCotroller...];
}
makes sense?
and yes, you should add a delegate-propery to your controller if not done yet