I'm writing an app and getting this error. Not sure how I would go about fixing it. Thank you.
The error is an undeclared identifier 'collectionView'
And the header file is being imported.
Header:
#import <UIKit/UIKit.h>
NSMutableData *content;
#interface AMCollectionViewController : UICollectionViewController
#property (weak, nonatomic) IBOutlet UIBarButtonItem *tagButton;
- (IBAction)tagButtonTouched:(id)sender;
#end
Implementation where error is occurring
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath
{
if(shareEnabled){
//determine the selected items by using the indexPath
NSString *selectedPhotos = [tagImages[indexPath.section] objectAtIndex:indexPath];
//add selected image into the array
[selectedPhotos addObject:selectedPhotos];
}
}
Thanks a lot guys
I use collectionView multiple times in the same .m file
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 50;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier =#"Cell";
AMCollectionViewCell *cell = (AMCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
int imageNumber = indexPath.row % 10;
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"imageicon%d.jpg",imageNumber]];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"imageBorder.jpg"]];
return cell;
}
I don't know about that error, but
Your second reference to indexPath on this line can't be right:
NSString *selectedPhotos = [tagImages[indexPath.section] objectAtIndex:indexPath];
The objectAtIndex parameter needs an integer. You probably meant:
NSString *selectedPhotos = [tagImages[indexPath.section] objectAtIndex:indexPath.item];
or, to be more consistent (either use objectAtIndex or use the [] syntax, but using both is a little curious):
NSString *selectedPhotos = tagImages[indexPath.section][indexPath.item];
You haven't shown the declaration of tagImages, nor it's initialization, but I assume it is tagImages an array of an array of strings? If so, the above correction should fix it. If not, you should tell us how tabImages is populated/structured.
If selectedPhotos is a NSString, the use of the addObject method won't possibly work. The addObject method is a NSMutableArray method, not a NSString method.
Related
I am trying to use collection view and display static images in that, but I get the following error:
[UICollectionViewCell imageView]: unrecognized selector sent to instance.
I have configured cell identifire = Cell.
Here is my code:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
SSCollectionViewCell *cell = (SSCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
int imageNumber = indexPath.row % 10;
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"Image%d.jpg",imageNumber]];
return cell;
}
here is the sscollectionViewCell.h code
#interface SSCollectionViewCell : UICollectionViewCell
#property (weak) IBOutlet UIImageView *imageView;
#end
here is the SSColletionViewCell.m code
#import "SSCollectionViewCell.h"
#interface SSCollectionViewCell ()
#end
#implementation SSCollectionViewCell
#synthesize imageView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#end
Can any one suggest where i made mistake.?
Change
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
To
[self.collectionView registerClass:[SSCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
You missed this in the ViewDidLoad Method
[self.collectionView registerClass:[SSCollectionViewCell class] forCellWithReuseIdentifier:#"Cell"];
Your cell is still a UICollectionCell and not your custom SSCollectionViewCell, It´s for that does´t know the message (unrecognized selector).
Look in stroryboard, be sure the select the collectionCell, and change it´s class (third tab in right menu), in CustomClass put your now.
I am trying to use UICollectionView to show the first 10 photos from my facebook profile. However, whenever I run the app, the UICollectionView does not show anything - it remains black and I dont see any cells. (I have set the background colour of the cells to blue and colour of the CollectionView to black, but I dont even see the blue cells)
I am using SDWebImage to load photos onto the cells.
Thank you in advance for any help
Here is my code:
In my header file -
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#interface LNViewController : UIViewController <FBFriendPickerDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
#end
In my .m file -
#import "LNViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#property (weak, nonatomic) IBOutlet UICollectionView *photoCollectionView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self refreshArray];
//fetch photos from facebook (this function also has [self.photoCollectionView reloadData] in it;
[self fetchPhotosMe];
[self.photoCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"photoCell"];
[self.photoCollectionView reloadData];
}
#pragma Mark UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = #"photoCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
//create array with URLs
NSMutableArray *photosURL = [[NSMutableArray alloc] init];
for (int i = 0; i <10; i++){
NSDictionary *photoDic = [self.photosMeArray objectAtIndex:i];
[photosURL addObject:[photoDic valueForKey:#"src"]];
}
//Load Cells
UIImageView *photoImageView = (UIImageView *)[cell viewWithTag:100];
[photoImageView setImageWithURL:[NSURL URLWithString:[photosURL objectAtIndex:indexPath.row]]];
return cell;
}
The didSelectRowAtIndexPath not working.
Have I configured the 2 delegates. Everything is linked (tableview, tableviewcell).
Already deleted and did it again.
I searched for everything here and nothing worked.
I think this was one of the best link, still to no avail.
My last hope is that it is, I'm opening my ViewController, where has this tableview, for modal. But it would be VERY wrong the problem.
Other than that, I need some help
Somo codes .H
#interface simulator : UIViewController <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
{
NSArray *array_products;
}
#property (nonatomic, strong) NSDictionary *plist_products;
#property (nonatomic, strong) IBOutlet UITableView *table_menu_left;
#property (nonatomic, strong) NSString *file_plist;
#end
Some codes .M
#import "cel_products.h"
- (void)viewDidLoad
{
NSString *path_root = [[NSBundle mainBundle] bundlePath];
NSString *full_path = [path_root stringByAppendingPathComponent:self.file_plist];
self.plist_products = [[NSDictionary alloc] initWithContentsOfFile:full_path];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"id_cell_products";
UITableViewCell *cell = [self.table_menu_left dequeueReusableCellWithIdentifier:CellIdentifier];
array_products = [self.plist_produtcs allKeys];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"cel_products" owner:self options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[cel_products class]])
{
cell = (cel_products *)currentObject;
break;
}
}
}
cell.textLabel.text = [array_products objectAtIndex:indexPath.row];
return cell;
}
// numberofrowsinsection - OK
// numberofsectionintableviw - OK
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Hein?????");
// Nothing..........
}
I humbly thousand apologies to all!
I inadvertently clicked Attributes Inspector> Selection: NO SELECTION
So I do not find anything in the code.
Again, I apologize to everyone, but if someone, are having this problem, this is one more step to be verified. " Change to Attributes Inspector> Selection: SINGLE SELECTION or MULTIPLE SELECTION ( is up to you )
Thanks all for the answers and help
Did you set a break at didSelectRowAtIndexPath? Try and see if it breaks successfully there.
Expanding on rokjark's answer you have to manually set the delegate and data source to the file in question.
Your header file simulator.h simply declares it as A delegate/data source for SOME UITableView.
You still need to point table_menu_left to use simulator.h as THE delegate file to handle all of it's callbacks.
Set:
self.table_menu_left.delegate = self;
self.table_menu_left.datasource = self;
And again set a break in didSelectRowAtIndexPath and see if it gets called.
I am using a UITableView that points to a UITabBarController to display a series of UIWebViews within these tabs.
I would like define a string to be used to construct a URL for each tab based on the item selected. The issue I am facing is how to pass the URL to the StateTrendViewController controller.
StateTableViewController.h
#import <UIKit/UIKit.h>
#interface StateTableViewController : UITableViewController
{
NSArray *StateList;
}
#property (nonatomic, retain) NSArray *StateList;
- (void) buildStateList;
#end
StateTableViewController.m
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [StateList 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];
}
NSInteger rowNumber = indexPath.row;
NSString *stateName = [StateList objectAtIndex:rowNumber];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = stateName.capitalizedString;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSInteger rowNumber = indexPath.row;
NSString *stateName = [StateList objectAtIndex:rowNumber];
[[self.navigationController.viewControllers objectAtIndex:2] setTitle:stateName.capitalizedString];
}
StateTrendViewController.h
#import <UIKit/UIKit.h>
#interface StateTrendViewController : UIViewController
{
IBOutlet UIWebView *StateTrendView;
IBOutlet NSString *ViewURL;
}
#property (nonatomic, retain) UIWebView *StateTrendView;
#property (nonatomic, retain) NSString *ViewURL;
#end
StateTrendViewController.m
#import "StateTrendViewController.h"
#implementation StateTrendViewController
#synthesize StateTrendView;
#synthesize ViewURL;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void) viewWillAppear:(BOOL)animated
{
NSString *baseURL = #"https://www.google.com/search?q=";
NSString *state = #"test";
NSString *fullURL = [baseURL stringByAppendingString:state];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [StateTrendView loadRequest:requestObj];
}
I need to replace the static setting with the sting passed to the controller using the ViewURL property I have setup:
NSString *state = #"test";
I am using a Storyboard in my project in Xcode 4.2.1. How should I go about passing that string value to my controller?
You override prepareForSegue, more detail is here
If all you are passing is a string, the simplest way might be to define a property on your the view controller you are presenting to hold the string. I notice you already have one, *ViewURL defined, but I'm not sure if that's what you've setup for this specific task or if that is already intended for something else.
Based on the code you've shared, I'm assuming that in your didSelectRowAtIndexPath in your table controller, the controller you are setting the title, and presumably later pushing, is an instance of a StateViewController:
[[self.navigationController.viewControllers objectAtIndex:2] setTitle:stateName.capitalizedString];
If this line does indeed reference an instance of StateTrendViewController, you would assign your string in the same way you're assigning title. This needs to be set before you segue into the new view controller (I don't see that code):
[[self.navigationController.viewControllers objectAtIndex:2] setViewURL:#"MyPassedString"] //assign custom property
When your view controller appears on screen, it will have it's property ViewURL already set.
Also note that your naming style for instance variables is not a standard cocoa convention, ivars beginLowerCase. Additionally, it is unusual and may not work to push a TabBar controller inside an existing nav controller, presumably from table view view controller inside an existing nav controller. Typically a TabBar is considered a top-level navigational construct, and you may wish to rethink your architecture accordingly.
I know this has been asked over and over again. I've tried all given solution but still it didn't work. I have set the datasource and delegate to my table view and also set it to my pointers.
Here is my code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(#"%i", resultSoap.count);
return resultSoap.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] autorelease];
}
// Configure the cell.
NSString *cellValue = [resultSoap objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
NSLog(#"Celldisplay");
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
I've called the reloadData on my viewDidLoad: method. The thing is, it fired numberOfRowsInSection: method and I get the row count correct but it didn't fire this cellForRowAtIndexPath: method.
Any solution?
Use this code:
urtableview.delegate = self;
urtableview.datasource = self;
After declaring the resultsoap array in your code.
It must be due to calling reload method of table when table view datasource array "resultsoap" is empty.
Make sure that your datasource array is not empty and check if the array has objects saved.
Because if numberOfRowsInSection returns 0 then the cellForRowAtIndexPath may not be called.
And this must be in your case.
Please Add Bellow Code In Your Suitable Methods.
if You had take Simple Controller and Add Table View than
In your Header File .h
#import <UIKit/UIKit.h>
#interface TaskAndTax : UIViewController<UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *MyTableView;
}
#property (nonatomic, retain) UITableView *MyTableView;
#end
And in Your .m File
#synthesize MyTableView;
-(void) viewWillAppear:(BOOL)animated
{
[MyTableView reloadData];
}
And Kindly Connect IBOutlet Of TableView in Our Case its MyTableView to TableView in XIB file.