Hi i am very new for ios and in my project i am using PageViewController
for displaying and swiping the images,Ok that's fine
But here i am loading images on my pageViewcontroller from services(i mean url images i am loading)
For this i am using SDWebImage library for loading images,But here i have underlined clearly where i am getting errors below in my RootViewController.m please help me how can i load images in PageViewController using SDWebImage library and what is the wrong in that line please help me
my code:-
PageContentViewController.h
#interface PageContentViewController: UIViewController
#property (weak,nonatomic) IBOutlet UIImageView * ivScreenImage;
#property NSUInteger pageIndex;
#property NSString *imgFile;
#property NSString *txtTitle;
#end
PageContentViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.ivScreenImage.image = [UIImage imageNamed:self.imgFile];
}
RootViewController.h
#import <SDWebImage/UIImageView+WebCache.h>
#interface RootViewController : UIViewController
<UIPageViewControllerDataSource>
#property (nonatomic,strong) UIPageViewController *PageViewController;
#property (nonatomic,strong) NSArray *arrPageImages;
- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index;
#end
RootViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
arrPageImages =#[#"http://www.domain.com/path/to/image1.jpg",#"http://www.domain.com/path/to/image2.jpg",#"http://www.domain.com/path/to/image3.jpg"];
}
- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index{
if (([self.arrPageTitles count] == 0) || (index >= [self.arrPageTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageContentViewController"];
pageContentViewController.imgFile setImageWithURL:[[[NSURL URLWithString:[self.arrPageImages[index]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
--------------------------------------------------------------------------------
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
SDWebImage method for setting image for UIImageView is
sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
also imgFile variable should be UIImageView.
Related
this question is based on the apple x-code tutorial here.
I am having an error when I call my unwindBusList function which looks at the source of the segue. I have tested it with these lines commented out and everything else seems to run fine other than the BusStopItem not being added.
Property of BusStopItem' not found on type
'AddBusStopViewController'
on this line:
BusStopItem *item = source.busStopItem;
YourBusStopsTableViewController.m
#import "YourBusStopsTableViewController.h"
#import "BusStopItem.h"
#import "AddBusStopViewController.h"
#interface YourBusStopsTableViewController ()
#property NSMutableArray *busStopItems;
- (IBAction)unwindBusList:(UIStoryboardSegue *)segue;
#end
#implementation YourBusStopsTableViewController
- (IBAction)unwindBusList:(UIStoryboardSegue *)segue {
AddBusStopViewController *source = segue.sourceViewController;
BusStopItem *item = source.busStopItem;
if (item != nil) {
[self.busStopItems addObject:item];
[self.tableView reloadData];
}
}
AddBusStopViewController.h
#import <UIKit/UIKit.h>
#import "BusStopItem.h"
#interface AddBusStopViewController : UIViewController
#property BusStopItem *busStopItem;
#end
AddBusStopViewController.m
#import "AddBusStopViewController.h"
#interface AddBusStopViewController ()
#property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;
#property (weak, nonatomic) IBOutlet UITextField *stopNumField;
#property (weak, nonatomic) IBOutlet UITextField *nameField;
#end
#implementation AddBusStopViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if (sender != self.saveButton) return;
if (self.nameField.text.length > 0 && self.stopNumField.text.length > 0) {
self.busStopItem = [[BusStopItem alloc] init];
self.busStopItem.itemName = self.nameField.text;
self.busStopItem.stopNum = [self.stopNumField.text intValue];
self.busStopItem.fetching = NO;
}
}
#end
BusStopItem.h
#import <Foundation/Foundation.h>
#interface BusStopItem : NSObject
#property NSString *itemName;
#property NSInteger stopNum;
#property BOOL fetching;
#end
Any and all feedback is appreciated, this has been bugging me for hours, and nothing has solved my problem.
Thanks in Advance.
The problem was that the objective-c files I created for the views were not in the appropriate directory. Although they appeared in xcode to be in the correct location (and actually were), these versions weren't being updated as I was saving. I replaced the files that were not being written to with the appropriate ones and everything works.
I have two storyboards and each one has its own respective view controller but I need to change the appearance of the second storyboard based on the button pressed in the first view controller.
In the first view controller I have:
// First view controller .h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
#interface FirstViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIButton *LevelOneButton; // tag 0
#property (strong, nonatomic) IBOutlet UIButton *LevelTwoButton; // tag 1
-(IBAction)selectLevel:(UIButton *)sender; // both buttons connected to this method
#property (assign, nonatomic) int levelSelect;
#end
then in the first .m file:
//FirstViewController.m
-(IBAction)selectLevel:(UIButton *)sender {
if (sender.tag == 0) {
_levelSelect = 0;
}
if (sender.tag == 1) {
_levelSelect = 1;
}
}
This code works fine but the problem occurs in the secondViewController that I have. When I try and access the levelSelect property in the SecondViewController I get the errors "Property 'levelSelect' not found on object of type 'FirstViewController'" or "Unexpected identifier levelSelect" or something among those lines. I've tried every single thing I could think of and every question I found on StackOverflow relating to this but none have fixed the problem. Anyone know what I'm doing wrong?
You should be setting the property on the second view controller as you're pushing or segueing.
So in your first view controller it should look something like this:
#import "ViewController.h"
#import "SecondViewController.h"
#interface ViewController ()
#property (strong, nonatomic) IBOutlet UIButton *levelOne;
#property (strong, nonatomic) IBOutlet UIButton *levelTwo;
#property (assign, nonatomic) int selectedLevel;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.levelOne.tag = 1;
self.levelTwo.tag = 2;
}
- (IBAction)selectLevel:(UIButton *)sender
{
if (sender.tag == 1) {
self.selectedLevel = 1;
} else {
self.selectedLevel = 2;
}
[self performSegueWithIdentifier:#"pushToSecond" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SecondViewController *dest = segue.destinationViewController;
dest.levelSelect = self.selectedLevel;
}
#end
Now, when viewDidLoad gets called on the SecondViewController that property will be set and you can use it. Like so:
#import "SecondViewController.h"
#interface SecondViewController ()
#property (strong, nonatomic) IBOutlet UILabel *levelLabel;
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.levelLabel.text = [#(self.levelSelect) stringValue];
}
#end
Quick Edit, if you're not using segues you can do the same thing by pushing manually. Would look something like:
- (IBAction)selectLevel:(UIButton *)sender
{
if (sender.tag == 1) {
self.selectedLevel = 1;
} else {
self.selectedLevel = 2;
}
SecondViewController *secondVC = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"second"];
secondVC.levelSelect = self.selectedLevel;
[self.navigationController pushViewController:secondVC animated:YES];
}
Writing my first iphone app through this tutorial--I have a custom UIView with the method showDie and I have two UIView elements on my storyboard that I've hooked up to my ViewController. However, both the UIView elements have the error message "No visible #interface for 'UIView' declares the selector 'showDie'. I think that's because the UIViews aren't subclassing XYZDieView, but when I control-clicked from my Storyboard, only UIView appeared in the dropdown--no XYZDieView. I tried just changing the text manually in the ViewController.h, but that didn't work (I didn't think it would). Am I on the right track? How do I use my subclass? (xcode 5)
XYZDieView.m
-(void)showDie:(int)num
{
if (self.dieImage == nil){
self.dieImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
[self addSubview:self.dieImage];
}
NSString *fileName = [NSString stringWithFormat:#"dice%d.png", num];
self.dieImage.image = [UIImage imageNamed:fileName];
}
XYZViewController.h
#import <UIKit/UIKit.h>
#import "XYZDieView.h"
#interface XYZViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *sumLabel;
#property (strong, nonatomic) IBOutlet UIButton *rollButton;
#property (strong, nonatomic) IBOutlet UIView *leftDieView;
#property (strong, nonatomic) IBOutlet UIView *rightDieView;
#end
XYZViewController.m
#import "XYZViewController.h"
#import "XYZDiceDataController.h"
#interface XYZViewController ()
#end
#implementation XYZViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)rollButtonClicked:(UIButton *)sender {
XYZDiceDataController *diceDataController = [[XYZDiceDataController alloc] init];
int roll = [diceDataController getDiceRoll];
int roll2 = [diceDataController getDiceRoll];
[self.leftDieView showDie:roll];
[self.rightDieView showDie:roll2];
int sum = roll + roll2;
NSString *sumText = [NSString stringWithFormat:#"Sum is %i", sum];
self.sumLabel.text = sumText;
}
#end
Yes you're right, the problem is subclassing. In order to have a view conform to a subclass in the interface builder you need to
Click on the UIView in your storyboard
Open the right inspector panel
Click on the third tab for identity inspector
Add your class
Then try to connect it to your ViewController again.
Edit: Afterwards you may need to cast XYZDieView myView = (XYZDieView*)leftDieView;
I saw a lot of this kind of questions and answers here, but couldn't find solution to my problem. I'm trying to send data from one view controller to another and use delegate. But don't know why my postDelegate doesn't responds to selector. Is something wrong with this code or what is the problem?
PostViewController.h file
#protocol GetDataDelegate <NSObject>
-(void)getPassedInfo:(NSString*)info;
#end
#interface PostViewController : UIViewController
#property (nonatomic, weak) id <GetDataDelegate> postDelegate;
#end;
PostViewController.m file
#import "PostViewController.h"
- (IBAction)postData:(id)sender {
if ([_postDelegate respondsToSelector:#selector(getPassedInfo:)]) {
[self.postDelegate getPassedInfo:#"data"];
NSLog(#"responds");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
in second view controllers .h file
#import "PostViewController.h"
#interface MainViewController : UITableViewController <GetDataDelegate>
and in .m file
#implementation MainWindowTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
PostViewController * postController = [[PostViewController alloc]init];
postController.postDelegate = self;
}
and here is delegate method:
-(void)getPassedInfo:(NSString *)info{
NSLog(#"info is %#", info);
}
You need to make postController a property or an ivar. Currently it is a local variable in the viewDidLoad method which will be deallocated after viewDidLoad completes as #CodaFi said above.
#import "PostViewController.h"
#interface MainViewController : UITableViewController <GetDataDelegate>
#property (nonatomic, strong) PostViewController *postController;
#end
Then:
- (void)viewDidLoad
{
[super viewDidLoad];
self.postController = [[PostViewController alloc]init];
self.postController.postDelegate = self;
}
I am trying to pass an image from my TableViewController to a DetailViewController. My problem is a logic problem i guess because Xcode doesn't show any error in my code. When i tap on any row and takes me to the DetailView, the DetailView shows nothing and i want the DetailView to show me the image i am passing.
My TableViewController.h
#import <UIKit/UIKit.h>
#import "CustomCellControllerCell.h"
#import "DetailViewController.h"
#interface ListViewController : UITableViewController
#property (nonatomic) NSArray *foodImgArray;
#property (nonatomic) NSArray *foodTitleArray;
#end
My TableViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.foodTitleArray = #[#"manito",
#"jatito",
#"dolorsito",
#"pajarito",
#"calalito",
#"chinguito"];
self.foodImgArray = #[#"ajigallina.jpg",
#"anticucho.jpg",
#"causaRellena.jpg",
#"anticucho.jpg",
#"anticucho.jpg",
#"anticucho.jpg"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"detailView"]) {
DetailViewController *dvc = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
dvc.passedImage.image = [UIImage imageNamed:[self.foodImgArray objectAtIndex:indexPath.row]];
}
}
My DetailViewController.h
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *detailImage;
#property (nonatomic) UIImageView *passedImage;
#end
And my DetailViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.detailImage.image = self.passedImage.image;
}
why dont you just pass a image
like--
dvc.image=[UIImage imageNamed:[self.foodImgArray objectAtIndex:indexPath.row]];
and set that image to detailImage in DetailViewController like--
self.detailImage.image = self.image
try to put some break point to check if image in not nil in DetailViewController.