views:

450

answers:

0

Hey guys,

I am quite new to iPhone development but I am trying to build a small medical app.

The app consists of tab bar controller and in the first item is a navigation controller and a grouped UITableView. The problem is that scrolling the table on my iPhone 3G is pretty slow. It is not so smooth like in the Settings app. The performance in the Simulator is normal.

I did a lot of searching and reading through Apple's documentation but I don't know what the problem is.

Thanks for any advice in advance!

//
//  UnfallTableViewController.h

#import <UIKit/UIKit.h>

@class UnfallDetailViewController;


@interface UnfallTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
 UITableView *unfallTableView;
 NSMutableArray *notfallArray;
 NSMutableArray *weitereArray;
 UnfallDetailViewController *unfallDetailViewController;
}

@property (nonatomic, retain) NSMutableArray *notfallArray;
@property (nonatomic, retain) NSMutableArray *weitereArray;
@property (nonatomic, retain) UnfallDetailViewController *unfallDetailViewController;

@end

//
//  UnfallTableViewController.m

#import "UnfallTableViewController.h"
#import "UnfallDetailViewController.h"
#import "HomAid_004AppDelegate.h"


@implementation UnfallTableViewController

@synthesize notfallArray;
@synthesize weitereArray;
@synthesize unfallDetailViewController;

- (void)viewDidLoad {
    [super viewDidLoad];

 self.title = NSLocalizedString(@"Unfall", @"Unfall Titel");

 NSMutableArray *array1 = [[NSMutableArray alloc] 
         initWithObjects:
         @"Haus", @"Freizeit", @"Verkehr", nil];
 NSMutableArray *array2 = [[NSMutableArray alloc] 
         initWithObjects:
         @"Eins", @"Zwei", @"Drei",
         @"Vier", @"Fünf", @"Sechs",
         @"Sieben", @"Acht", @"Neun",
         @"Zehn", @"Elf", @"Zwölf", nil];

 self.notfallArray = array1;
 self.weitereArray = array2;

 [notfallArray release];
 [weitereArray release];

 UIBarButtonItem *info = [[UIBarButtonItem alloc] 
        initWithTitle:@"Notruf"
        style:UIBarButtonItemStyleBordered
        target:self action:@selector(sosCall:)];

 self.navigationItem.rightBarButtonItem = info;
}

- (void)sosCall:(id)sender {
 NSLog(@"Notruf Button gedrückt");

 UIApplication *app = [UIApplication sharedApplication];
 NSString *urlString = [NSString stringWithFormat:@"tel:123456789"];
 NSURL *url = [NSURL URLWithString:urlString];
 [app openURL:url];
}

- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 self.notfallArray = nil;
 self.weitereArray = nil;
 self.unfallDetailViewController = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 0)
  return [notfallArray count];
 else
  return [weitereArray count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *UnfallTableIdentifier = @"UnfallTableIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UnfallTableIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
     initWithStyle:UITableViewCellStyleDefault 
     reuseIdentifier:UnfallTableIdentifier] autorelease];
    }

 NSUInteger row = [indexPath row];

 if(indexPath.section == 0)
  cell.textLabel.text = [notfallArray objectAtIndex:row];
 else
  cell.textLabel.text = [weitereArray objectAtIndex:row];

 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
 NSUInteger row = [indexPath row];
 if (self.unfallDetailViewController == nil) {
  UnfallDetailViewController *unfallDetail = [[[UnfallDetailViewController alloc] 
             initWithNibName:@"UnfallDetailView" 
             bundle:nil] autorelease];
  self.unfallDetailViewController = unfallDetail;
 }

 if(indexPath.section == 0)
  unfallDetailViewController.title = [NSString stringWithFormat:@"%@", [notfallArray objectAtIndex:row]];
 else
  unfallDetailViewController.title = [NSString stringWithFormat:@"%@", [weitereArray objectAtIndex:row]];

 [self.navigationController pushViewController:unfallDetailViewController animated:YES];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
 if (section == 0)
  return @"Notfall";
 else
  return @"weitere Unfälle";
}

- (void)dealloc {
 [unfallTableView release];
 [notfallArray release];
 [weitereArray release];
 [unfallDetailViewController release];
    [super dealloc];
}

@end