UISwitch Graphical Artifact - objective-c

i have made a normal UISwitch programmatically in objective c inside a UITableViewCell and when i go to view it in the simulator i see this:
Why is it happening and how can i fix it?
Here is the code for how i am implementing it:
UISwitch Class:
#import <Foundation/Foundation.h>
#interface SwitchCell : UITableViewCell
+ (SwitchCell*)SwitchCellMake;
#end
#implementation SwitchCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
+ (SwitchCell*)SwitchCellMake{
SwitchCell * newSwitchCell = [[SwitchCell alloc]init];
UISwitch * cellSwitch = [[UISwitch alloc] init];
[newSwitchCell.contentView addSubview:cellSwitch];
[cellSwitch setCenter:CGPointMake(600, 30)];
return newSwitchCell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
[super setSelected:selected animated:animated];
}
#end
ViewDidLoad:
- (void)viewDidLoad{
[super viewDidLoad];
[arySwitchCells addObject:[SwitchCell SwitchCellMake]];
}
And the cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
SwitchCell *cellSwitchCell = (SwitchCell *)[tableView dequeueReusableCellWithIdentifier:#"SwitchCell"];
cellSwitchCell = [arySwitchCells objectAtIndex:indexPath.row];
return cellSwitchCell;
}

Why do you try to allocate this cell every single time? You should dequeue it. I try this code and it works fine for me:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UISwitch * cellSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(200, 10, 50, 50)];
[cell.contentView addSubview:cellSwitch];
return cell;
}
Just remember to set up cell identifier.
//EDITED
I would remove SwitchCellMake method and add UISwitch to the contentView in initWithStyle:reuseIdentifier method (or initWithCoder if you use nib):
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.cellSwitch = [[UISwitch alloc] init];
[self.contentView addSubview:self.cellSwitch];
}
return self;
}
As you can see cellSwitch is a property so you can set up the frame in layoutSubview (you can handle the orientation changing here):
-(void)layoutSubviews
{
[self.cellSwitch setFrame:CGRectMake(200, 10, 50, 50)];
}
After that just register your cell in storyboard or in viewDidLoad (if you don't use nib) and change your init method to:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SwitchCell *cellSwitchCell = (SwitchCell *)[tableView dequeueReusableCellWithIdentifier:#"Cell"];
cellSwitchCell.textLabel.text = [NSString stringWithFormat:#"Row: %d", indexPath.row];
return cellSwitchCell;
}
This is how I would do this.

Related

UIGestureRecognizer in UITableViewCell

I'd like to add UIGestureRecognizer to UITableViewCell.
When I call panAction: in CustomCell class, it will work.
But I'd like to call the method in ViewController class, and in this case, it will not work.
How do I fix it to work panAction:?
- (void)viewDidLoad
{
_tableView = [[UITableView alloc]initWithFrame:self.view.frame];
_tableView.delegate = self;
_tableView.dataSource = self;
[_tableView registerClass:[CustomCell class] forCellReuseIdentifier:#"Cell"];
[self.view addSubview:_tableView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *nibName = #"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:nibName];
if (!cell) {
cell = (CustomCell*)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nibName];
}
return cell;
}
- (void)setupGesture
{
UIPanGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(panAction:)];
CustomCell* cell = (CustomCell*)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[cell addGestureRecognizer:panRecognizer];
}
- (void)panAction:(UIPanGestureRecognizer *)sender
{
CGPoint location = [sender translationInView:sender.view];
NSLog(#"%f", location);
[sender setTranslation:CGPointZero inView:sender.view];
}
In the code posted above, you don't call setupGesture. This way your cell won't pick up the gestures. Also, you should just add create and add panRecognizer to the cell in tableview:cellForRowAtIndexpath: like so:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *nibName = #"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:nibName];
UIPanGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(panAction:)];
[cell addGestureRecognizer:panRecognizer];
return cell;
}

How cell swipe on clicking a button

I want to swipe cell on click a button . I am succesful on swiping a cell. But i want to swipe on button which is in cell. my code is
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleCell";
SimpleCell *cell = (SimpleCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
SimpleCell *cekks=[[SimpleCell alloc]init];
cekks.scrollButton.alpha =0.0;
NSString *titleString;
UIButton *sender = [[UIButton alloc]init];
//[sender setBackgroundImage:[UIImage imageNamed:#"swipe.png"] forState:UIControlStateNormal];
sender.tag = indexPath.row;
titleString =#"Send A Gift";
UITableViewRowAction *sendAGift = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:titleString handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// [self deleteMail:[NSArray arrayWithObject:indexPath]:YES];
}];
[sendAGift setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"swipe.png"]]];
return #[sendAGift];
}
I think your class SimpleCell should contain the UIButton, in order perform reusing correctly.
It will be simpler if you create a custom UITableViewCell that contains all the UI actions over the cell and operate them within the cell, not in the UITableView itself.
Let's see an example:
Here's the customCell.h file:
#interface customCell : UITableViewCell {
UIButton *buttonSwipe;
}
#end
Here's the customCell.h file:
#import "customCell.h"
#implementation customCell
- (instancetype) initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
}
- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self commonInit];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}
- (void) commonInit {
buttonSwipe = [UIButton... // Initialize here your button
[buttonSwipe addTarget:self action:#selector(swipeCell:) forControlEvents:UIControlEventTouchUpInside];
}
- (void) swipeCell {
// Embed here the code that makes the effect of swipe the cell.
}
This is a fast-untested workaround with some predefined code, but I think it's a working example if you want to make your cells swipe with your own code.
But if you want a faster way, I recommend you to visit Chris Wendel and his SWTableViewCell on GitHub
You can call editActionsForRowAtIndexPath: method as
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:SELECTED_ROW_INDEX inSection:0];
[self tableView:self.tableView editActionsForRowAtIndexPath:indexPath];
try the below code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
//swipe button allocation
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
btn.tag = indexPath.row;
[cell.contentView addSubview:btn];
[btn addTarget:self action:#selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
cell.textLabel.text = [NSString stringWithFormat:#"%lu",indexPath.row];
return cell;
}
-(void)buttonTouched:(id)sender{
UIButton *btn = (UIButton *)sender;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:btn.tag inSection:0];
[self tableView:self.tableView editActionsForRowAtIndexPath:indexPath];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"edit");
// code
return nil;
}

Unable to reloaddata(UITableView)

I'm creating a UITableView in an UIView controller
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 470, self.view.frame.size.height) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
NSLog(#"tableView is '%#'",self.tableView);
}
the NSLog result :"tableView is '< UITableView: 0x7c60c00; frame = (0 0; 470 1004); clipsToBounds = YES; gestureRecognizers = ; layer = ; contentOffset: {0, 0}>'"
the refreshTableView method will be called, when the itemArray is modified by other controller
**SideBarViewController *sideBarViewController = [[SideBarViewController alloc]init];
[sideBarViewController refreshTableView];**
-(void)refreshTableView {
[self createItemArray];
NSLog(#"reload itemArray->%#",self.itemArray);
NSLog(#"tableView is '%#'",self.tableView);
[self.tableView reloadData];
}
somehow, the NSLog result become:"tableView is '(null)'". and the tableView won't be reloaded.
why? please help. thanks.
Update:
the NSLog of itemArray was fine:
before change
reload itemArray->(
"test.md"
)
after change
reload itemArray->(
"test.md",
"test2.md"
)
Update2:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.itemArray 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];
}
cell.textLabel.text = [self.itemArray objectAtIndex:indexPath.row];
return cell;
}
update 3:
.h
#interface SideBarViewController : UIViewController<IIViewDeckControllerDelegate,UITableViewDataSource,UITableViewDelegate>
.m
#interface SideBarViewController ()
#property (nonatomic,strong) UITableView *tableView;
#end
#implementation SideBarViewController
#synthesize tableView = _tableView;
update 4:
the
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
method is working fine, after deleted rows the tableview was reloaded.
Share some more code so we can find the exact issue.
can you check the actual name of your tableView? share some code of the table you have declared in .h file.
Check array, data is available before reload or update and table view methods are working fine.
Check you define tableView delegates in .h file or not? And implement delegate methods of tableView in your class properly..
#interface MyViewController:UIViewController
And one more thing check you have properly implemented your data source and delagate methods.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.
If you have done this thing correctly then check your array before load it contains data or not. May be this will help you.
You can try to use Notification
add Observer into you viewDidLoad in Sidebarvc
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(refreshTableView:)
name:#"dataChanged"
object:nil];
create a method to refresh
-(void)refreshTableView:(NSNotification *)notif{
}
on the other VC,just wait for the notification
[[NSNotificationCenter defaultCenter] postNotificationName:#"dataChanged"
object:nil];
4.don't forget to clean it
add [[NSNotificationCenter defaultCenter] removeObserver:self]; to ViewDidUnload
Should work.
//
// ViewController.h
// tableData
//
// Created by Nirav Jain on 3/28/13.
// Copyright (c) 2013 SI. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
int rows;
}
#end
// tableData
//
// Created by Nirav Jain on 3/28/13.
// Copyright (c) 2013 SI. All rights reserved.
//
#import "ViewController.h"
//#implementation SideBarViewController
#interface ViewController ()
#property (nonatomic,strong) UITableView *tableView;
#end
#implementation ViewController
#synthesize tableView = _tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 470, self.view.frame.size.height) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
NSLog(#"tableView is '%#'",self.tableView);
rows = 5;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:#selector(refreshTableView)];
}
-(void)refreshTableView {
rows = 12;
NSLog(#"tableView is '%#'",self.tableView);
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return rows;
}
- (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];
}
cell.textLabel.text = [ NSString stringWithFormat: #"%d", indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

Push the values to new ViewController when a cell is tapped

I have table view that populated with plist called "Htgg".
I am trying to push the value to a new view called "DetailViewController".
This is the code:
#import "Glist.h"
#import "DetailViewController.h"
#implementation Glist
#synthesize htgg,detailViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"ofek", #"ofek");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = #"איך להוציא גימלים?";
NSString *htggFile = [[NSBundle mainBundle]pathForResource:#"Htgg" ofType:#"plist"];
htgg = [[NSDictionary alloc] initWithContentsOfFile: htggFile];
}
- (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 [htgg 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];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
id keys = [htgg allKeys];
//Get all the keys in the first dictionary (the keys are: "good", "funny", "New - Item 3")
//This is an array, so you can do this: array[0] (in C#)
//Here we tell the tableview cell. to put in the text - [keys objectsAtIndex:indexPath.row]; if the row is 0, we will get: "good", if 1, we will get "funny"
cell.textLabel.text = [keys objectAtIndex:indexPath.row];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *showPickedSolution = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:showPickedSolution animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#end
The code works perfect but it doesn't push the value of the row( all the rows of plist are string type and above the there is 'Root').
I need your help to push the value to another view(DetailViewController).
make a property in your DetailViewController of the same type as of your data you want to push then use
DetailViewController *showPickedSolution = [[DetailViewController alloc]
initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
showPickedSolution.yourPropertName = [htgg objectAt:indexPath.Row];
[self.navigationController pushViewController:showPickedSolution animated:YES];
you can now access the passed dat in your DetailViewController in your property.
Please check the syntax.
I have done this in two different way depending on the scenario:
1) Delegate, when I fill some values on a form that I want to pass back to the original screen.
2) Storyboard Segue, when I want to send some value(s) to a second screen.
I usually put all the values I want in an array to send the object and then at arrival I extract what I need.
Instead of explaining each way, I can refer you to Getting Started section of the iOS Dev Site.
I hope it help!
To achieve this you can made an NSString property in class DetailViewController and set that property in didSelectRowAtIndexPath. Here is the code for your reference:
showPickedSolution.valueToBeSent = [htgg valueForKey:[[htgg allKeys] objectAtIndex:indexPath.row]];
You can use this valueToBeSent in your DetailViewController class.

Why is TableView not showing anything.

I have a class with a tableView. I get no build errors, but when I try to run the app, after I add a new item, nothing appears to happen. Here's the code:
In .h
#interface entriesViewController : UIViewController <UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *TableView;
-(IBAction)startEditing:(id)sender;
-(IBAction)newItem:(id)sender;
#end
In .m
#import "entriesViewController.h"
#import "LEItemStore.h"
#import "LEItem.h"
#interface entriesViewController ()
#end
#implementation entriesViewController
#synthesize TableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[TableView setDelegate:self];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[TableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)startEditing:(id)sender {
if ([TableView isEditing])
{
[TableView setEditing:NO animated:YES];
}
else
{
[TableView setEditing:YES animated:YES];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[LEItemStore sharedStore] allItems] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"UITableViewCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"UITableViewCell"];
}
LEItem *p = [[[LEItemStore sharedStore] allItems]objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[p description]];
return cell;
}
-(IBAction)newItem:(id)sender {
LEItem *newItem = [[LEItemStore sharedStore] createItem];
[TableView reloadData];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
LEItemStore *ps = [LEItemStore sharedStore];
NSArray *items = [ps allItems];
LEItem *p = [items objectAtIndex:[indexPath row]];
[ps removeItem:p];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
[[LEItemStore sharedStore] moveItemAtIndex:[sourceIndexPath row] toIndex:[destinationIndexPath row]];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSArray *items = [[LEItemStore sharedStore] allItems];
//BNRItem *selectedItem = [items objectAtIndex:[indexPath row]];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self TableView]reloadData];
}
It would appear as if the TableView isn't reloading it's data. By the way, all connections have been made. Absolutely nothing appears. Just my Toolbar, the TableView does not change even after I added an item.
Ok so after clearing this in the comments, your problem is that you haven't set the data source (you can also do this with an array controller).
So you set the delegate and the data source:
[TableView setDelegate:self];
[TableView setdataSource: self];
Then you declare the class to also implement the UITableViewDataSource protocol.
And you provide the two fondamental methods (also optional methods are welcome):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
This is an example of a simple data source implementation that just has one label saying hello:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell=[[UITableViewCell alloc]init];
UILabel* label= cell.textLabel;
label.text= #"Hello";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
But now you know how to provide a more complex data source: if you have an array you can read the index path and then set the label using the objectAtIndex method.
I am not sure about this, but if you are using controller as data source then you need to specify interface for UITableViewDataSource.
Try changing:
#interface entriesViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
Set delegate and dataSource for tableView in viewDidLoad to controller instance e.g.
TableView.delegate = self;
TableView.dataSource = self;
You can also implement UITableViewDataSource interface on LEItemStore classs. If you do so, then you need to set dataSource property to instance of LEItemStore.
TableView.delegate = self;
TableView.dataSource = [LEItemStore sharedStore];