#import "sideTableViewController.h"
#interface sideTableViewController ()
{
NSArray *colours;
}
#end
#implementation sideTableViewController
#synthesize colorNames;
#synthesize sideTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.sideTableView.delegate= self;
self.sideTableView.dataSource=self;
colorNames = [NSArray arrayWithObjects:#"Archie",#"Sethi",#"Rajan" ,#"Deepak" ,nil];
}
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section
{
return [colorNames count];
}
- (UITableViewCell *)sideTableView:(UITableView *)sideTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [sideTableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyCell"];
}
cell.textLabel.text =[colorNames objectAtIndex:indexPath.row];
// NSLog(#"the indexpath is %#",indexPath);
return cell;
}
- (void)sideTableView:(UITableView *)sideTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [sideTableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[sideTableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and this is the header file...
#import <UIKit/UIKit.h>
#interface sideTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *colorNames;
}
#property (strong, nonatomic) IBOutlet UITableView *sideTableView;
-(IBAction)showMessage;
#property (nonatomic, retain) NSArray *colorNames;
#end
I'm trying to get an image as a background to an existing tableview.
i'm getting an exception regarding: [sideTableViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7593640
please help i'm new in IOS programming!
may this code help you simply add the below code to just above
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section
add this code
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
Related
I cannot seem to find my error can anyone help me? When I attempt to run test the application it works but when I click on the Calendar segue it shows me a blank uitableview list. I want it to show me the "event" in the text
My NSLOG details about the array:
2014-08-08 17:38:28.391 nths[2899:607] array contents: (
" {\n Date = \"9/14/14\";\n Information = \"Mrs. Ford's Room\";\n event = Meeting;\n}",
" {\n Date = \"9/14/19\";\n Information = \"ford room\";\n event = \"lunch at bravos\";\n}"
)
Here are is all of the code that I think would affect this.
CalendarViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "DataCellViewController.h"
#interface CalendarViewController : UIViewController <UITableViewDelegate> {
NSArray *eventArray;
}
#property (weak, nonatomic)IBOutlet UITableView *Datatable;
#end
CalendarViewController.m
#import "CalendarViewController.h"
#interface CalendarViewController ( )
#end
#implementation CalendarViewController
#synthesize Datatable;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self performSelector:#selector(retrieveFromParse)];
}
- (void) retrieveFromParse {
PFQuery *retrieveDate = [PFQuery queryWithClassName:#"Calendar"];
[retrieveDate findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(#"%#",objects);
if (!error) {
eventArray = [[NSArray alloc] initWithArray:objects];
}
[Datatable reloadData];
}];
}
//Setup table of folder names
//get number of sections in tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
//get number of rows by counting number of folders
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return eventArray.count;
}
//setup cells in tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//setup cell
static NSString *CellIdentifier = #"CalenderCell";
DataCellViewController *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[DataCellViewController alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSDictionary *tempDict = [eventArray objectAtIndex:indexPath.row];
cell.eventTitle.text = [tempDict objectForKey:#"event"];
NSLog(#"array contents: %#", eventArray);
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
DataCellViewController.h
#import <UIKit/UIKit.h>
#interface DataCellViewController : UITableViewCell
#property (nonatomic, strong)IBOutlet UILabel *eventTitle;
#end
DataCellViewController.m
#import "DataCellViewController.h"
#interface DataCellViewController ( )
#end
#implementation DataCellViewController
#synthesize eventTitle;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
I'm having a bit confusion with the UITableViewCellStyle. I want to create a custom UITableViewCell like this:
But the text and the image not appear in the cell when I run the app. In Storyboard,I've put the TableView Style to 'Custom'.
What am I doing wrong?
MainTableViewController
#import "MainTableViewController.h"
#import "CustomMainCell.h"
static NSString *CellIdentifier = #"MainCell";
#interface MainTableViewController ()
//
#property(nonatomic, strong) NSArray *dataSource;
//
#property(nonatomic, strong) NSArray *iconsSource;
#end
#implementation MainTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Currículum Vitae";
// Inicializo los arrays con los datos
self.dataSource = #[#"PERFIL",#"EXPERIENCIA",#"EDUCACIÓN",#"HABILIDADES",#"INTERESES"];
self.iconsSource = #[#"perfil.png",#"experiencia.png",#"educacion.png",#"habilidades.png",#"intereses"];
// Register Class for Cell Reuse Identifier
[self.tableView registerClass:[CustomMainCell class] forCellReuseIdentifier:CellIdentifier];
// This will remove extra separators from tableview
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// Eliminio las líneas que separan las celdas
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomMainCell *cell = (CustomMainCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CustomMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.title.text = self.dataSource[indexPath.row];
cell.icon.image = self.iconsSource[indexPath.row];
return cell;
}
CustomMainCell.h
#interface CustomMainCell : UITableViewCell
//
#property (weak, nonatomic) IBOutlet UILabel *title;
//
#property (weak, nonatomic) IBOutlet UIImageView *icon;
#end
CustomMainCell.m
#import "CustomMainCell.h"
#implementation CustomMainCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.textLabel.textColor = [UIColor brownColor];
}
return self;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
You shouldn't have:
// Register Class for Cell Reuse Identifier
[self.tableView registerClass:[CustomMainCell class] forCellReuseIdentifier:CellIdentifier];
because the cell is registered from the storyboard when the view controller is unarchived. By registering the class you are removing the archive (NIB) registration.
Additionally:
if (cell == nil) {
cell = [[CustomMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
shouldn't be required as you will always get a valid cell back (because the identifier is registered)
I am trying to add a simple button to a custom cell that has a web link. I added the button in story board and associated it with houseLink. Here is my view.M file where I call the button from the custom cell.
#import "IBSecondViewController.h"
#import "C21TableCell.h"
#interface IBSecondViewController ()
#end
#implementation IBSecondViewController
{
NSArray *thumbnails;
}
#synthesize data;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Initialize House Array
data = [NSArray arrayWithObjects:#"2109 E Avon Cricle, Hayden Lake, ID", #"703 E Garden, Coeur d' Alene, ID", nil];
_bedroom = [NSArray arrayWithObjects:#"3", #"4", nil];
// Initialize thumbnails
thumbnails = [NSArray arrayWithObjects:#"stockHouse.png", #"stockHouse2.png", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view ddata source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"C21TableCell";
C21TableCell *cell = (C21TableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"C21TableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.addressLabel.text = [data objectAtIndex:indexPath.row];
cell.bedroomLabel.text = [_bedroom objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
NOT SURE HOW TO CALL THE BUTTON HERE
return cell;
}
-(void) buttonpressed:(UIButton *)sender {
NSString* launchUrl = #"http://apple.com/";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
#end
C21TableCell.H
#import <UIKit/UIKit.h>
#interface C21TableCell : UITableViewCell
#property (nonatomic, weak) IBOutlet UILabel *addressLabel;
#property (nonatomic, weak) IBOutlet UILabel *bedroomLabel;
#property (nonatomic, weak) IBOutlet UIImageView *thumbnailImageView;
#property (nonatomic, weak) IBOutlet UIButton *homeLink;
#end
C21TableCell.M
#import "C21TableCell.h"
#implementation C21TableCell
#synthesize addressLabel = _nameLabel;
#synthesize bedroomLabel = _bedroomLabel;
#synthesize thumbnailImageView = _thumbnailImageView;
#synthesize homeLink = homeLink;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
Just add target to button action when you create cell
[cell.homeLink addTarget:self action:#selector(buttonpressed:) forControlEvents:UIControlEventTouchUpInside];
I do not understand to this but always when I try to launch my app, I get error.
Can someone help me? I think it will be maybe something in TableeViewController.m. But i am not sure.
Thanks
TableCell.h
#import < Parse/Parse.h >
#interface TableCell : PFTableViewCell
#property (strong, nonatomic) IBOutlet UILabel *cellTitle;
#property (strong, nonatomic) IBOutlet UILabel *cellDescript;
#end
TableCell.m
#import "TableCell.h"
#implementation TableCell
#synthesize cellTitle;
#synthesize cellDescript;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
TableeView.h
#import <Parse/Parse.h>
#import "TableCell.h"
#import "DetailViewController.h"
#interface TableeViewController : PFQueryTableViewController {
NSArray *colorsArray;
}
#property (strong, nonatomic) IBOutlet UITableView *colorsTable;
#end
TableeViewController.m
#import "TableeViewController.h"
#import "TableCell.h"
#import "DetailViewController.h"
#interface TableeViewController ()
#end
#implementation TableeViewController #synthesize colorsTable;
- (void) retrieveFromParse {
PFQuery *retrieveColors = [PFQuery queryWithClassName:#"Hracky1"];
[retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
colorsArray= [[NSArray alloc] initWithArray:objects];
}
[colorsTable reloadData];
}];
[self.colorsTable reloadData];
[self.refreshControl endRefreshing]; }
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self; }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return colorsArray.count; }
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:#selector(retrieveFromParse)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject
*)object {
TableCell *cell = (TableCell * )[self.tableView dequeueReusableCellWithIdentifier:#"colorsCell"
forIndexPath:indexPath];
NSString * cellTitle = [object objectForKey:#"cellTitle"];
NSString * cellDescript = [object objectForKey:#"cellDescript"];
cell.cellTitle.text = cellTitle;
cell.cellDescript.text = cellDescript;
return cell; }
#end
It looks like you have subclassed the PFTableViewCell and created the properties "cellTitle" and "cellDescription" but you haven't initialized and added them them in TableCell.
There seems to be no reason to subclass the PFTableViewCell if you are not making any changes to it. You can actually just use the normal UITableViewCell.
So, delete "TableCell" and create the cells by using a UITableViewCell:
static NSString *simpleTableIdentifier = #"ColorsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
}
Then you can access the properties "textLabel" and "detailTextLabel" by doing this:
cell.textLabel.text = [object objectForKey:#"cellTitle"];
cell.detailTextLabel.text = [object objectForKey:#"cellDescript"];
Follow this tutorial from beginning to end and you'll get there:
http://www.appcoda.com/ios-programming-app-backend-parse/
Good luck!
I'm trying to make a Master-Detail app that displays a list of Sounds on the master view. When you tap the sound, you go to the detail screen, and it displays the Sound you chose as a label, then shows a short movie of the sound. My problem is, all the sounds show as the label the name of the first sound in the list. When I tap on Sound B, the detail screen shows "Sound B." When I tap on tSound F, the detail screen shows "Sound B."
No errors or warnings come up. Any ideas?
Thanks in advance.
slfViewController.h
#import <UIKit/UIKit.h>
#interface slfViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, strong) IBOutlet UITableView *tableView;
#end
slfViewController.m
#import "slfViewController.h"
#import "slfSoundDetailViewController.h"
#interface slfViewController ()
#end
#implementation slfViewController
{
NSArray *tableData;
NSArray *thumbnails;
}
#synthesize tableView = _tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
tableData = [NSArray arrayWithObjects:
#"B Sound",
#"Ch Sound",
#"D Sound",
#"F Sound",
...
#"Zh Sound",
nil];
thumbnails = [NSArray arrayWithObjects:
#"b.jpg",
#"ch.jpg",
#"d.jpg",
#"f.jpg",
...
#"zh.jpg",
nil];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showSoundDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
slfSoundDetailViewController *destViewController = segue.destinationViewController;
destViewController.soundName = [tableData objectAtIndex:indexPath.row];
}
}
#pragma mark - TableView Data Source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"soundCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
return cell;
}
#end
slfSoundDetailViewController.h
#import <UIKit/UIKit.h>
#interface slfSoundDetailViewController : UIViewController
#property (nonatomic, strong) IBOutlet UILabel *soundLabel;
#property (nonatomic, strong) NSString *soundName;
#end
slfSoundDetailViewController.m
#import "slfSoundDetailViewController.h"
#interface slfSoundDetailViewController ()
#end
#implementation slfSoundDetailViewController
#synthesize soundLabel;
#synthesize soundName;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
soundLabel.text = soundName;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
You’re only setting soundLabel.text = soundName in viewDidLoad… so it’s only being called once (when the view controller’s view is first loaded). This app is most likely reusing the same instance of slfSoundDetailViewController so it doesn’t reload its view.
You’ll probably want to override either -[slfSoundDetailViewController setSoundName:] or -[slfSoundDetailViewController viewWillAppea:] and set soundLabel.text there.