MWPhotoBrowser will not display photo - ios

I'm trying to implement MWPhotoBrowser in my project. I've added all the delegates, but it still will not display the photo.
Here's my didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"MWPhotoBrowserSegue" sender:self]
}
This is my segue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue identifier] isEqualToString:#"MWPhotoBorwserSegue"])
{
photoBrowser = [[MWPhotoBrowser alloc]initWithDelegate:self];
UINavigationController * nc = [[UINavigationController alloc]initWithRootViewController:photoBrowser];
nc.modalTransitionStyle = UIModalTransitionStyleCrossDisolve;
[photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:#"picasa.jpg"]];
[photoBrowser setCurrentPhotoIndex:0];
[self.navigationController presentViewController:nc animated:YES completion:nil];
}
}
The #ofPhotosInBrowser:
-(NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
{
return self.photos.count;
}
photoAtIndex:
- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
if (index < self.photos.count)
return [self.photos objectAtIndex:index];
return nil;
}
Here's what I get after the didSelectRowAtIndexPath: is called:
Edit for Solution:
MWPhotoBrowser will not display a photo unless you put self.title in the initWithStyle: method. I also forgot to add the viewWillDisappear and viewWillAppear

I think u need to call reload data on it. Check Mwphotobrowser.h for proper way to do it.

try this [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:yourNewNavigationController animated:YES completion:nil];
}];

Related

How to pass data from one ViewController to another after using Segue?

I went from one ViewController to another using Segue in my second viewController has an UITableView. now, I want to push from second ViewController's didSelected method to another viewController.
code use to Segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
SearchVC *svc = segue.destinationViewController;
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
}
under button action:
-(void) searchButtonClicked:(id)sender {
[self performSegueWithIdentifier:#"search" sender:nil];
}
And the main problem arise here, can't navigate using below code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PackageListVC *pdvc = (PackageListVC *)[self.storyboard instantiateViewControllerWithIdentifier:#"PackageListVC"];
pdvc.strServiceProviderId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:#"ServiceProviderId"] stringValue];
pdvc.strCategoryId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:#"CategoryId"] stringValue];
pdvc.strSubCategoryId = [[[arrSearch objectAtIndex:indexPath.row] objectForKey:#"SubCategoryId"] stringValue];
pdvc.strTitle = [[arrSearch objectAtIndex:indexPath.row] objectForKey:#"CompanyName"];
[self.navigationController pushViewController:pdvc animated:YES];
}
You do it in the prepareForSegue method.
where you declare svc (SearchVC *svc = segue.destinationViewController;) you can say something like:
svc.variable = 1;

dismissViewControllerAnimated is not dissmissing ViewController

So....I have a View Controller and when I press a button, another View Controller appears:
- (IBAction)searchButtonPressed:(id)sender {
[self presentViewController:self.controllerSearch animated:YES completion:nil];
}
Inside view controller number 2 is a table view and when a row is selected in a table this code runs:
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSString *filePath2 = filePath; assert(filePath2 != nil); // Path to first PDF file
LazyPDFDocument *document = [LazyPDFDocument withDocumentFilePath:filePath2 password:phrase];
if (document != nil) // Must have a valid LazyPDFDocument object in order to proceed with things
{
LazyPDFViewController *lazyPDFViewController = [[LazyPDFViewController alloc] initWithLazyPDFDocument:document];
lazyPDFViewController.delegate = self; // Set the LazyPDFViewController delegate to self
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
[self.navigationController pushViewController:lazyPDFViewController animated:YES];
#else // present in a modal view controller
lazyPDFViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
lazyPDFViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:lazyPDFViewController animated:YES completion:NULL];
#endif // DEMO_VIEW_CONTROLLER_PUSH
}
else // Log an error so that we know that something went wrong
{
NSLog(#"%s [LazyPDFDocument withDocumentFilePath:'%#' password:'%#'] failed.", __FUNCTION__, filePath2, phrase);
}
Now I am using LazyPDFKit and it comes with this delegate method:
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
// dismiss the modal view controller
[self dismissViewControllerAnimated:YES completion:NULL];
}
I put a break point and I can see my code goes into the delegate method, but the LazyPDFViewController does not go away.
I have tried the following:
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
but that takes me back a few view controllers to far.
Am I missing something?
Additional code in my first view Controller .h
#property (strong, nonatomic) UISearchController *controllerSearch;
and in first view controller .m
- (UISearchController *)controller {
if (!_controllerSearch) {
// instantiate search results table view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
LHFileBrowserSearch *resultsController = [storyboard instantiateViewControllerWithIdentifier:#"SearchResults"];
// create search controller
_controllerSearch = [[UISearchController alloc]initWithSearchResultsController:resultsController];
_controllerSearch.searchResultsUpdater = self;
// optional: set the search controller delegate
_controllerSearch.delegate = self;
}
return _controllerSearch;
}
If you are pushing the view controller:
[self.navigationController pushViewController:lazyPDFViewController animated:YES];
Then the code in the delegate doesn't make sense, because it assumes it is a modal view controller that needs to be dismissed:
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
// dismiss the modal view controller
[self dismissViewControllerAnimated:YES completion:NULL];
}
But you've added it to the navigation stack (I assume).
If you can't pop it again from the navigation controller at this point you are missing some code in your example.
Are you sure your delegate is firing on the main thread? Try:
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
}
try this:
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
// dismiss the modal view controller
[[viewController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
your code :
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
just went too far.
I just made the demo project based on your situation. And I am not facing any issue with it. So I think there might be some issue regarding how you are presenting the second controller.
In your button click, try this code:
- (IBAction)searchButtonPressed:(id)sender {
UIStoryboard *main = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
//idSecondVC is the storyboard id of second view controller
SecondVC *SecondVC = [main instantiateViewControllerWithIdentifier:#"idSecondVC"];
[self presentViewController:SecondVC animated:YES completion:nil];
}
And in your controller number 2, I just used the above code:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [NSString stringWithFormat:#"Cell %ld",indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self openLazyPDF];
}
- (void)openLazyPDF
{
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:#"pdf" inDirectory:nil];
NSString *filePath = [pdfs firstObject]; assert(filePath != nil); // Path to first PDF file
LazyPDFDocument *document = [LazyPDFDocument withDocumentFilePath:filePath password:phrase];
if (document != nil) // Must have a valid LazyPDFDocument object in order to proceed with things
{
LazyPDFViewController *lazyPDFViewController = [[LazyPDFViewController alloc] initWithLazyPDFDocument:document];
lazyPDFViewController.delegate = self; // Set the LazyPDFViewController delegate to self
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
[self.navigationController pushViewController:lazyPDFViewController animated:YES];
#else // present in a modal view controller
lazyPDFViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
lazyPDFViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:lazyPDFViewController animated:YES completion:NULL];
#endif // DEMO_VIEW_CONTROLLER_PUSH
}
else // Log an error so that we know that something went wrong
{
NSLog(#"%s [LazyPDFDocument withDocumentFilePath:'%#' password:'%#'] failed.", __FUNCTION__, filePath, phrase);
}
}
#pragma mark - LazyPDFViewControllerDelegate methods
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
// dismiss the modal view controller
[self dismissViewControllerAnimated:YES completion:NULL];
}
And for me everything is working fine.
Looks like you need to the same macro for present as dismiss. So, you wrote
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
[self.navigationController pushViewController:lazyPDFViewController animated:YES];
#else // present in a modal view controller
lazyPDFViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
lazyPDFViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:lazyPDFViewController animated:YES completion:NULL];
#endif // DEMO_VIEW_CONTROLLER_PUSH
You thus need
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
[self.navigationController popViewControllerAnimated:YES];
#else // presented in a modal view controller
[self dismissViewControllerAnimated:YES completion:NULL];
#endif // DEMO_VIEW_CONTROLLER_PUSH
It's possible that you have switched off the main thread and you can always add an assert to be check or, as has been suggested, use a dispatch_async to be certain.
NSAssert([NSThread isMainThread)];
I prefer the assert, when I know all the flows through a piece of code, since it shows my assumptions to the future me (or another) and does not leave code that looks like it knows something I do not (oh, they are using dispatch_async onto main so there must be some other thread magic going on deeper down).
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
if (![NSThread isMainThread])
{
dispatch_async(dispatch_get_main_queue(), ^
{
[self dismissLazyPDFViewController:viewController];
});
return;
}
if (viewController.navigationController)
{
[viewController.navigationController popViewControllerAnimated:YES];
}
else
{
[viewController dismissViewControllerAnimated:YES completion:nil];
}
}

iPad - DetailViewController programmatically

I'm working on an iPad app where I use UISplitViewController. I also use DetailViewController in which to display some information from XML, but the information is not displayed in DetailViewController but in MaterViewController. I really do not know how to fix it. Can you please help. Thank you
There is code:
-(void) showDetailsForIndexPath:(NSIndexPath*)indexPath
{
[self.searchBar resignFirstResponder];
DetailViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailsViewController"];
Slova* slova;
if(isFiltered)
{
slova = [filteredTableData objectAtIndex:indexPath.row];
}
else
{
slova = [self.slovoArray objectAtIndex:indexPath.row];
}
vc.slovoItem = slova;
[self.navigationController pushViewController:vc animated:true];
}
The reason is that you're pushing the new UIViewController onto the stack for self, which is presumably the MasterViewController. Instead, create a new project using Apple's Master-Detail Application and you'll see how they do it.
Caveat: they use Storyboards, but it is very possible to do this all in code.
In Apple's example, both the MasterViewController and the DetailViewController are visible from the start (in landscape).
Look how Apple's example sets detailItem (slovoItem?) for DetailViewController:
#pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = self.objects[indexPath.row];
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
[controller setDetailItem:object];
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
controller.navigationItem.leftItemsSupplementBackButton = YES;
}
}
So, you'll have DetailViewController already visible and you'll just update its detailItem property.
Therefore, the following code exists in DetailViewController:
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}

tableview segue to another view controller

I am new to programming and am probably hung up on a simple problem. I am using parse for my array in my tableview. When the row is selected i want to segue to a search bar on another view controller. The segue works fine and the tableview works fine but i can't seem to get the objectId to pass.
#import "bookmarkViewController.h"
#import "Parse/Parse.h"
#import <ParseUI/ParseUI.h>
#import "ViewController.h"
#implementation bookmarkViewController
#synthesize postArray;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self
action:#selector(refreshButtonHandler:)]];
}
- (void)viewWillAppear:(BOOL)animated
{
if ([PFUser currentUser])
[self refreshButtonHandler:nil];
}
#pragma mark - Button handlers
- (void)refreshButtonHandler:(id)sender
{
//Create query for all Post object by the current user
PFQuery *postQuery = [PFQuery queryWithClassName:#"Post"];
[postQuery whereKey:#"author" equalTo:[PFUser currentUser]];
// Run the query
[postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//Save results and update the table
postArray = objects;
[self.tableView reloadData];
}
}];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
// Return the number of rows in the section.
return postArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell with the textContent of the Post as the cell's text label
PFObject *post = [postArray objectAtIndex:indexPath.row];
[cell.textLabel setText:[post objectForKey:#"textContent"]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
NSLog(#"cell tapped");
PFObject *post = [postArray objectAtIndex:indexPath.row];
NSLog(#"%#", post.objectId);
[self performSegueWithIdentifier:#"searchBookmark" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ViewController *vc = [segue destinationViewController];
vc.labelText = post.objectId;
}
}
#end
at vc.label.text i always get use of undeclared identifier "post" but i can't seem to figure out how to get it recognized. It is in the above method.
the NSLogs reply correctly 16:17:27.513 [App] cell tapped
[App] cgdVY7Eu9h
Change your didSelectRowAtIndexPath and prepareForSegue to this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath* )indexPath{
[self performSegueWithIdentifier:#"searchBookmark" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSLog(#"cell tapped");
PFObject *post = [postArray objectAtIndex:indexPath.row];
NSLog(#"%#", post.objectId);
ViewController *vc = [segue destinationViewController];
vc.labelText = post.objectId;
}
}
Post is a local variable that you created inside didSelectRowAtIndexPath, so it can't be used outside that method. The easy way to fix this, is to pass post as the sender argument in performSegueWithIdentifier:sender:. You can pass any object you want as the sender.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
NSLog(#"cell tapped");
PFObject *post = [postArray objectAtIndex:indexPath.row];
NSLog(#"%#", post.objectId);
[self performSegueWithIdentifier:#"searchBookmark" sender:post];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
PFObject *post = (PFObject *)sender;
ViewController *vc = [segue destinationViewController];
vc.labelText = post.objectId;
}
UIViewController -> segue -> UITableViewController
I had one problem that i solved with answer -1- Thanks.
So i had a kind of UIViewController and i wanted with button just segue to another UITableViewController and i noticed that it stacked and was frozen. I could not scroll my Table ...
My Code was :
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
MasterViewController *controller =segue.destinationViewController;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:controller animated:YES completion:nil];
}
My CPU was over 100% overloaded.
So the answer number 1 worked for me well. New Code is then :
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
MasterViewController *vc = [segue destinationViewController];
}
and the table with 30 entries works now just like a charm =)

Using didSelectRowAtIndexPath

I have a table with 5 cells and if the user clicks my second cell for example, I want to show another table or another page.
Is using
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath`
the way ?
Here is an example of navigating to another view controller when the user clicks on the second cell (assuming you have a navigation controller):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 1){
MyViewController * vc = [[MyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
}
sample Link :http://www.tutorialspoint.com/ios/ios_ui_elements_tableview.htm
if (indexPath.row ==1)
{
//Second cell index path its move another class xib
classname *yourcontroller = [[classname alloc] initWithNibName:#"xib file name" bundle:nil];
yourcontroller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:helpcontroller animated:YES completion:nil];
}
If you are using a Storyboard, you may skip tableView:didSelectRowAtIndexPath: and use prepareForSegue:sender: instead:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"__SEGUE_IDENTIFIER__"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SomeOtherViewController *vc = (SomeOtherViewController *)segue.destinationViewController;
// assign something to vc
}
}

Resources