iOS: no se puede establecer el texto de UILabel
k, déjenme explicar la situación, tengo dos controladores de vista, llamémoslos primero y segundo.
FirstViewController hereda de UITableViewControllerSecondViewController hereda de UIViewControllerLa interfaz para SecondViewController está hecha con Interface Builder y contiene simplemente una etiqueta y un UIProgressView. tanto la etiqueta como la salida UIProgressView están conectadas con el propietario correcto de los archivos (SecondViewController).
un poco de código, en FirstViewController:
el siguiente método se activa mediante una notificación
- (void) addTransfer:(NSNotification *)notification{
NSLog(@"notification received");
NSDictionary *transferInfo = [notification userInfo];
// I think the problem is here
aTransfer = [[DbTransfer alloc] initWithNibName:@"DbTransfer" bundle:nil];
//
aTransfer.srcPath = [transferInfo objectForKey:@"srcPath"];
aTransfer.dstPath = [transferInfo objectForKey:@"dstPath"];
[aTransfer startTransfer];
[transfer addObject:aTransfer];
[self.tableView reloadData];
}
esos son los métodos tableView dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d numberOfRowsInSection",[transfer count]);
return [transfer 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] autorelease];
}
[cell.contentView addSubview:[[transfer objectAtIndex:indexPath.row] view]];
return cell;
}
este es el código de SecondViewController.h
@interface DbTransfer : UIViewController <DBRestClientDelegate> {
IBOutlet UILabel *fileNameLabel;
IBOutlet UIProgressView *transferProgress;
NSString *srcPath;
NSString *dstPath;
DBRestClient *restClient;
}
@property (nonatomic,retain) IBOutlet UILabel *fileNameLabel;
@property (nonatomic,retain) IBOutlet UIProgressView *transferProgress;
@property (nonatomic,retain) NSString *srcPath;
@property (nonatomic,retain) NSString *dstPath;
- (void) startTransfer;
@end
este es un método dentro de SecondViewcontroller.m
- (void) startTransfer{
//NSLog(@"%@\n%@",srcPath,dstPath);
if (!fileNameLabel) {
NSLog(@"null");
}
[self.fileNameLabel setText:[srcPath lastPathComponent]];
//self.fileNameLabel.text=@"test";
NSLog(@"%@",fileNameLabel.text);
restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate=self;
[restClient loadFile:srcPath intoPath:dstPath];
}
como puede ver dentro de startTransfer compruebo si fileNameLabel es nulo y lo es, y no entiendo por qué. Quizás el valor nulo esté relacionado con la asignación del iVar aTransfer. por cierto, es imposible establecer el texto de la etiqueta.