So I've been following this tutorial on creating In-App Purchases:
http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial
I'm stuck on the part where you actually display the in-app purchases in a tableView. I mean first of all he forgot to include the .h file for that view controller... so I have no idea what should be in there. But my problem is that the tableview loads fine but no data appears in it.
#import "UpgradeViewController.h"
#import "goIAPHelper.h"
#import <StoreKit/StoreKit.h>
#interface UpgradeViewController () {
NSArray *_products;
}
#end
#implementation UpgradeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"In-App Purchases";
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(reload) forControlEvents:UIControlEventValueChanged];
[self reload];
[self.refreshControl beginRefreshing];
}
// 4
- (void)reload {
_products = nil;
[self.tableView reloadData];
[[goIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
NSLog(#"Products: %#", _products);
[self.tableView reloadData];
}
else{
NSLog(#"Not Quite");
}
[self.refreshControl endRefreshing];
}];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// 5
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _products.count;
NSLog(#"products count: %d", _products.count);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
SKProduct * product = (SKProduct *) _products[indexPath.row];
cell.textLabel.text = product.localizedTitle;
NSLog(#"Product Title: %#", product.localizedTitle);
return cell;
}
#end
I get a response from the IAPHelper, but I put a lot of NSLogs in the table part of the code and it seems to never even get to that point. Log looks like this:
2015-09-10 11:51:37.905 go[1952:1075517] Not purchased: net.hawkinsd.go.noads
2015-09-10 11:51:37.905 go[1952:1075517] Not purchased: net.hawkinsd.go.pebbles
2015-09-10 11:51:39.377 go[1952:1075517] Loaded list of products...
2015-09-10 11:51:39.378 go[1952:1075517] Products: (
)
So it basically stops at the "Products" NSLog and doesn't seem to continue any further.
This is my UpgradeViewController.h file:
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#interface UpgradeViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
#end
Alright... so anyone who followed that guide (or similar guides) is likely to run into the same problem with the blank table.
Basically the table wasn't populating because iTunes wasn't returning the in-app items... and iTunes wasn't returning the in-app items because you're REQUIRED to have the banking and tax information filled-out.
Furthermore you're also required to have all of that filled out (and have already submitted your app) before iAds will work properly. So those are the conditions for which the table will populate.
Related
I followed this tutorial from AppCoda and I noticed that when I create another calendar, choose it (indicated by the checkmark beside it), then hit the Back button, the events in the main UIViewController view are not refreshed. I already added this code in my ViewController.m but nothing new happened:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (self.tblEvents == nil) {
NSLog(#"Your TableView becomes nil");
return;
}
[self.tblEvents reloadData];
}
Any ideas? Let me know if you need more information.
Edit:
.m
#import "MainViewController.h"
#import "AppDelegate.h"
#interface MainViewController ()
#property (nonatomic, strong) AppDelegate *appDelegate;
#property (nonatomic, strong) NSArray *arrEvents;
- (void)requestAccessToEvents;
- (void)loadEvents;
#end
#implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.tblEvents.delegate = self;
self.tblEvents.dataSource = self;
[self performSelector:#selector(requestAccessToEvents) withObject:nil afterDelay:0.4];
[self performSelector:#selector(loadEvents) withObject:nil afterDelay:0.5];
[self.tblEvents reloadData];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tblEvents reloadData];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"idSegueEvent"]) {
EventViewController *eventViewController = [segue destinationViewController];
eventViewController.delegate = self;
}
}
#pragma mark - UITableView Delegate and Datasource method implementation
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(#"%lu", (unsigned long)self.arrEvents.count);
return self.arrEvents.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"idCellEvent"];
// Get each single event.
EKEvent *event = [self.arrEvents objectAtIndex:indexPath.row];
// Set its title to the cell's text label.
cell.textLabel.text = event.title;
// Get the event start date as a string value.
NSString *startDateString = [self.appDelegate.eventManager getStringFromDate:event.startDate];
// Get the event end date as a string value.
NSString *endDateString = [self.appDelegate.eventManager getStringFromDate:event.endDate];
// Add the start and end date strings to the detail text label.
cell.detailTextLabel.text = [NSString stringWithFormat:#"%# - %#", startDateString, endDateString];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// Keep the identifier of the event that's about to be edited.
self.appDelegate.eventManager.selectedEventIdentifier = [[self.arrEvents objectAtIndex:indexPath.row] eventIdentifier];
// Perform the segue.
[self performSegueWithIdentifier:#"idSegueEvent" sender:self];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the selected event.
[self.appDelegate.eventManager deleteEventWithIdentifier:[[self.arrEvents objectAtIndex:indexPath.row] eventIdentifier]];
// Reload all events and the table view.
[self loadEvents];
}
}
#pragma mark - EEventViewControllerDelegate method implementation
- (void)eventWasSuccessfullySaved
{
// Reload all events.
[self loadEvents];
}
#pragma mark - IBAction method implementation
- (IBAction)showCalendars:(id)sender
{
if (self.appDelegate.eventManager.eventsAccessGranted) {
[self performSegueWithIdentifier:#"idSegueCalendars" sender:self];
}
}
- (IBAction)createEvent:(id)sender
{
if (self.appDelegate.eventManager.eventsAccessGranted) {
[self performSegueWithIdentifier:#"idSegueEvent" sender:self];
}
}
#pragma mark - Private method implementation
- (void)requestAccessToEvents
{
[self.appDelegate.eventManager.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (error == nil) {
// Store the returned granted value.
self.appDelegate.eventManager.eventsAccessGranted = granted;
} else {
// In case of error, just log its description to the debugger.
NSLog(#"%#", [error localizedDescription]);
}
}];
}
- (void)loadEvents
{
if (self.appDelegate.eventManager.eventsAccessGranted) {
self.arrEvents = [self.appDelegate.eventManager getEventsOfSelectedCalendar];
[self.tblEvents reloadData];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
To make UITableView work you need to set the delegate and datasource object like this..
in you ViewController.m file try to add Delegate and DataSource like this.
#interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
#end
now add these two lines in your view did load.
self.tblEvents.delegate = self;
self.tblEvents.dataSource = self;
And check the implimentation of you Data Source methods like this
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//This method should return the number of rows you want to create in your tableView
return yourArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"yourCellIdentifier"];
//Now show what you want to show in your each cell? For Example you just want to show a simple text which is stored in you array.
cell.textLabel.text = [yourArray objectAtIndex:indexPath.row];
//indexPath.row is the numeric index number of each cell. This method will automatically execute exact the same number of time you return in above method.
return cell;
}
Now When your class/View Controller is open you might have zero data in your array and after some manipulation you got some data in your array Either by Call Web-Services/Loading from local Database/ by Passing Reference of array to next ViewController and on coming back to screen you want to refresh your TableView so now calling [tblEvents reloadData] will restart the process from numberOfRowsInSection method to cellForRowAtIndexPath method
My Question is this. Why is the filtered table view showing rooms, after I start typing in the search bar that are not present when printing the filtered array to the console. I thought it might be that the table view cells are being reused so set the cell label text to nil to ensure the text gets reset in tableviewcellforindex: method , all to no avail. Can anyone help?
This is my Table View Controller that acts as the data source and delegate for for both my standard tableview and filtered tableview
#import <UIKit/UIKit.h>
#import "Rooms.h"
#interface RoomsTableViewController : UITableViewController
<UISearchControllerDelegate,UISearchResultsUpdating,UISearchBarDelegate,UITableViewDelegate>
#property (strong,nonatomic) NSMutableArray *roomList;
#property (strong,nonatomic) NSMutableArray *orderedRoomList;
#property (strong,nonatomic) NSMutableArray *filteredRooms;
#property (strong,nonatomic) UITableViewController *searchResultsController;
#property (strong,nonatomic) UISearchController *searchController;
#end
#import "RoomsTableViewController.h"
#interface RoomsTableViewController ()
#property BOOL searchControllerWasActive;
#property BOOL searchControllerSearchFieldWasFirstResponder;
#end
The implementation file
#implementation RoomsTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
//sort the room list into filetred by alpha numeric A10 before C1 example this will eventually be done on the server
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:#"name" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
return [(NSString *)obj1 compare:(NSString *)obj2 options:NSNumericSearch];
}];
self.orderedRoomList = (NSMutableArray*)[self.roomList sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
self.searchResultsController= [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
self.searchController = [[UISearchController alloc]initWithSearchResultsController:self.searchResultsController];
self.searchController.searchResultsUpdater=self;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView=self.searchController.searchBar;
//set up the data source and delegate of this new table view to be this (roomsTableviewcontroller) view controller
self.searchResultsController.tableView.delegate=self;
self.searchResultsController.tableView.dataSource=self;
self.searchController.delegate=self;
self.searchController.dimsBackgroundDuringPresentation=NO;
self.searchController.searchBar.delegate=self;
self.definesPresentationContext=YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//restore the search controllers active state
if (self.searchControllerWasActive) {
self.searchController.active = self.searchControllerWasActive;
_searchControllerWasActive=NO;
if (self.searchControllerSearchFieldWasFirstResponder) {
[self.searchController.searchBar becomeFirstResponder];
_searchControllerSearchFieldWasFirstResponder=NO;
}
}
}
-(void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
#pragma mark - UISearchControllerDelegate
- (void)willPresentSearchController:(UISearchController *)searchController {
// do something before the search controller is presented
self.navigationController.navigationBar.translucent = YES;
}
-(void)willDismissSearchController:(UISearchController *)searchController
{
self.navigationController.navigationBar.translucent = NO;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView==self.tableView) {
return [self.orderedRoomList count];
}else{
return [self.filteredRooms count];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 71;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellReuseIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier];
if (cell==nil) {
cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier];
}
Rooms *room = (tableView==self.tableView)? [self.orderedRoomList objectAtIndex:indexPath.row]: [self.filteredRooms objectAtIndex:indexPath.row];
cell.textLabel.text=nil;
NSString *labelString = [NSString stringWithFormat:#"%# %#",room.name,room.roomDescription];
cell.textLabel.text=labelString;
return cell;
}
Below is a photo of the table view in the simulator and a screen print of the check to see if the filtered array has indeed worked correctly as it has. You can see that C3 is not listed as being part of the filtered array but it still appears on screen.
Hi everyone beginner here.
I have a table view inside the ViewController. Content of the cell will be taken from parse.com. (A String) I already put necessary frameworks and set up a class in parse with a column and some rows.
I can tap the cells in simulator and when i add or delete new rows in parse the cells i can tap also changes.
But somehow the table turns empty, no label is displayed. I have no errors or issues.
Here is the code:
ViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "TableCell.h"
#interface ViewController : UIViewController <UITableViewDelegate> {
NSArray *Event;
}
#property (weak, nonatomic) IBOutlet UITableView *newsTable;
#end
ViewController.m
#import "ViewController.h"
#import "TableCell.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize newsTable;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self performSelector: #selector(retreiveFromParse)];
}
- (void) retreiveFromParse {
PFQuery *retrieveEvents = [PFQuery queryWithClassName:#"News"];
[retrieveEvents findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
Event = [[NSArray alloc] initWithArray:objects];
}
[newsTable 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 Event.count;
}
//setup cells in tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//setup cell
static NSString *CellIdentifier = #"EventCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PFObject *tempObject = [Event objectAtIndex:indexPath.row];
cell.TitleLabel.text = [tempObject objectForKey:#"TitleLabel"];
return cell;
}
//user selects folder to add tag to
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"cell tapped");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Few corrections -
First - it will be more appropriate to use a #property for the event array.
Second - it will be more appropriate to use Lowercased property name.
Your Array is not retained (it is nil), this is why you see nothing.
So, you should :
Add this to your interface -
#property (strong, nonatomic) NSArray *events;
Add this to your viewDidLoad, before you call retreiveFromParse
- (void)viewDidLoad
{
[super viewDidLoad];
self.events = [NSArray array];
// Do any additional setup after loading the view, typically from a nib.
[self performSelector: #selector(retreiveFromParse)];
}
That should work.
BTW
Parse has a TableViewController class that can simplify your work, look here -
Parse PFQueryTableViewController
I created a DetailViewController .h and .m files. Then I created a UITableViewController in the storyboard and connected it to the files I made.
Then I added this code to the DetailViewController.m file:
#import "MasterViewController.h"
#import "DetailViewController.h"
// 1
#import "RageIAPHelper.h"
#import <StoreKit/StoreKit.h>
// 2
#interface MasterViewController () {
NSArray *_products;
}
#end
#implementation MasterViewController
// 3
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"In App Rage";
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(reload) forControlEvents:UIControlEventValueChanged];
[self reload];
[self.refreshControl beginRefreshing];
}
// 4
- (void)reload {
_products = nil;
[self.tableView reloadData];
[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
[self.tableView reloadData];
}
[self.refreshControl endRefreshing];
}];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// 5
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _products.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
SKProduct * product = (SKProduct *) _products[indexPath.row];
cell.textLabel.text = product.localizedTitle;
return cell;
}
#end
But I get compile errors on lines like this:
self.refreshControl = [[UIRefreshControl alloc] init];
Saying that self.refreshControl is not recognized. But how can that be if the file is a UITableView file?
EDIT:
This is the .h
//
// DetailViewController.h
// entrepreneur
//
// Created by MacOSLion on 8/7/13.
// Copyright (c) 2013 MacOSLion. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface DetailViewController : UITableViewController
#end
I think you have a mistake somewhere...
See, you show us the implementation of :
#implementation MasterViewController
But the definition of :
#interface DetailViewController : UITableViewController
That's why, of course, it can't find refreshControl in MasterViewController : it is a property of UITableViewController, so of your DetailViewController.
Please tell me if it's not clear for you.
Add this to .h
#property (weak, nonatomic) UIRefreshControl *refreshControl;
I create a UITableViewController using storyboard, and want to reload the tableview every time it detect a device(for bonjour protocol).
However, the reload data method only calls numberofRows, but not call CellForRowatIndexPath. So I have nothing changed. The mutablearray I checked is always going correctly. NewObjects are added. But the tableview doesn't change with the array. So I am wondering if I set sth wrong here.
From the NSLog I added, I found, I could load the tableview at the beginning with
the initialized array
self.serviceArray = [[NSMutableArray alloc]initWithObjects:#"test", nil];
But in the method
- (void)addService:(NSNetService *)....
Everytime I reload, the new object can be added to the mutableArray, but the tableview doesn't change with the array. (It called the numberOfRows, and I check the array size returned is not 0, but then it doesn't call the cellOfRowAtIndex)
Here is my code
.h file
#import <UIKit/UIKit.h>
#import "Server.h"
#interface BrowserViewController : UITableViewController <ServerDelegate>
{
Server *_server;
NSMutableArray *_serviceArray;
}
#property (retain,nonatomic) NSMutableArray *serviceArray;
#property (nonatomic,retain) Server *server;
- (void)addService:(NSNetService *)service moreComing:(BOOL)more;
#end
.m file
#import "BrowserViewController.h"
#implementation BrowserViewController
#synthesize serviceArray = _serviceArray;
#synthesize server = _server;
- (void) dealloc
{
[self.serviceArray release];
[self.tableView release];
[super dealloc];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.title = #"Service Browser";
_serviceArray = nil;
self.serviceArray = nil;
[self.tableView setDelegate: self];
[self.tableView setDataSource:self];
//actually I set this in the storyboard already
[self.tableView reloadData];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
_serviceArray = nil;
NSLog(#"viewwilldisappear");
}
- (NSMutableArray *)serviceArray {
if(nil == _serviceArray) {
self.serviceArray = [[NSMutableArray alloc]initWithObjects:#"test", nil];
}
else
{
NSLog(#"update array");
}
return _serviceArray;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)addService:(NSNetService *)service moreComing:(BOOL)more{
[self.serviceArray addObject:service];
if (!more) {
[self.tableView reloadData];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return #"Connection Choices";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.serviceArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *Cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (Cell == nil) {
Cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
NSString *text = [self.serviceArray objectAtIndex:indexPath.row];
Cell.textLabel.text = text;
return Cell;
}
#end
I checked some solution, it's either delegate setting problem, or the array is null. or cell initialized without space. Is there any way to check what's the delegate of some method ?
I also tried to create a tableview property in the .h file, linked IBOutlet, then synthesize it in the .m. But still doesn't work. Could anyone help me?
Since a lot of tutorials are based on window-based application, could someone maybe provide me some tutorial using storyboard and using reloadData ? I could check if the Outlets are wrong.
Thanks in advance.
UPDATE1
AddService method is called in the appDelegate
appDelegate.h
#import <UIKit/UIKit.h>
#import "Server.h"
#class BrowserViewController;
#interface iphoneNetworkAppDelegate : NSObject <UIApplicationDelegate,UITableViewDataSource, UITableViewDelegate, ServerDelegate>
{
Server *_server;
UIWindow *window;
IBOutlet BrowserViewController *BrowserVC;
}
#property (strong, nonatomic) UIWindow *window;
#end
appDelegate.m
#import "iphoneNetworkAppDelegate.h"
#import "BrowserViewController.h"
#implementation iphoneNetworkAppDelegate
#synthesize window;
- (void)dealloc
{
[window release];
[_server release];
_server = nil;
[BrowserVC release];
BrowserVC = nil;
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *type = #"TestingProtocol";
_server = [[Server alloc] initWithProtocol:type];
_server.delegate = self;
NSError *error = nil;
if(![_server start:&error]) {
NSLog(#"error = %#", error);
}
BrowserVC = [BrowserViewController alloc];
if (BrowserVC == nil) {
NSLog(#"need to init");
}
BrowserVC.server = _server;
return YES;
}
#pragma mark Server Delegate Methods
- (void)serverRemoteConnectionComplete:(Server *)server {
NSLog(#"Server Started");
BrowserVC.server = server;
}
- (void)serverStopped:(Server *)server {
NSLog(#"Server stopped");
}
- (void)server:(Server *)server didNotStart:(NSDictionary *)errorDict {
NSLog(#"Server did not start %#", errorDict);
}
- (void)server:(Server *)server didAcceptData:(NSData *)data {
NSLog(#"Server did accept data %#", data);
}
- (void)server:(Server *)server lostConnection:(NSDictionary *)errorDict {
NSLog(#"Server lost connection %#", errorDict);
}
- (void)serviceAdded:(NSNetService *)service moreComing:(BOOL)more {
NSLog(#"service added in delegate");
[BrowserVC addService:service moreComing:more];
}
#pragma mark -
- (void)applicationWillTerminate:(UIApplication *)application {
[_server stop];
[_server stopBrowser];
}
If the appDelegate setting is like this, reloadData cannot be called ?
Please check this terms may help you:
self.tableView is object bind in TableView in XIB.
Included <UITableViewDelegate,UITableViewDataSource> delegates in .h file?
Properly set getter setter your object "self.tableView"
Delegate set?
a)[self.tableView setDelegate: self];
b)[self.tableView setDataSource:self];
i think No need for the following lines in view will appear
_serviceArray = nil;
self.serviceArray = nil;
And also makes sure that the function addService got called: