W
W
WizAlx2013-11-06 11:16:35
iOS
WizAlx, 2013-11-06 11:16:35

Working with TableView under iOS 7?

The problem is the following.
It is required to display the table in Alert. I run it through the iPhone 6.1 emulator, the method (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is picked up and everything works. On iOS 7, the environment does not seem to see this method. What could be the problem?
The code:

#import "AlertTableView.h"

@implementation AlertTableView

@synthesize  caller, context, data;

-(id)initWithCaller:(id)_caller data:(NSMutableArray *)_data title:(NSString *)_title andContext:(id)_context{
       
    NSString *messageString = @"\n\n\n\n\n\n";
    tableHeight = 125;
    
    
    
    self = [super initWithTitle:_title message:messageString delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
    if (self)
    {
        self.caller = _caller;
        self.context = _context;
        DLog(@"%@",_data);
        self.data = _data;
        [self prepare];
    }
    
    return self;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.caller didSelectRowAtIndex:-1 withContext:self.context];
}

-(void)show
{
    self.hidden = YES;
    [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(myTimer:) userInfo:nil repeats:NO];
    [super show];
}

-(void)myTimer:(NSTimer*)_timer
{
    self.hidden = NO;
    [myTableView flashScrollIndicators];
}

-(void)prepare
{
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(11, 50, 261, tableHeight) style: UITableViewStylePlain];
    if([data count] < 5)
    {
        myTableView.scrollEnabled = NO;
    }
    
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [self addSubview: myTableView];
    
    
    UIImageView *imgView = [[[UIImageView alloc] initWithFrame:CGRectMake(11, 50, 261, 4)] autorelease];
    imgView.image = [UIImage imageNamed:@"top.png"];
    [self addSubview:imgView];
    
    imgView = [[[UIImageView alloc] initWithFrame:CGRectMake(11, tableHeight + 46, 261, 4)] autorelease];
    imgView.image = [UIImage imageNamed:@"bottom.png"];
    [self addSubview:imgView];
    
    CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 10);

    [self setTransform:myTransform];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell*) [tableView dequeueReusableCellWithIdentifier: @"ABC"];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ABC"] autorelease];
        
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.textLabel.font = [UIFont boldSystemFontOfSize: 14];
        
    }
    cell.textLabel.text = [[data objectAtIndex:indexPath.row] description];
    DLog(@"%@",[[data objectAtIndex:indexPath.row] description]);
    return cell;
}


///////FOR DELETING

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // If row is deleted, remove it from the list.
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // delete your data item here
        // Animate the deletion from the table.
        [self.data removeObjectAtIndex: indexPath.row];
        [myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
        
        
        //delegate to del file with filename
        [self.caller didDeleteRowAtIndex: indexPath.row];
    }
}

/////////////

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self dismissWithClickedButtonIndex:0 animated:YES];
    [self.caller didSelectRowAtIndex:indexPath.row withContext:self.context];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [data count];
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

-(void)dealloc
{
    self.data = nil;
    self.caller = nil;
    self.context = nil;
    [myTableView release];
    [super dealloc];
}

@end

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
I
IgorFedorchuk, 2013-11-06
@WizAlx

I understand that AlertTableView inherits from UIAlertView? In this case, here is what is written in the Apple documentation.

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question