我在我的程序中创建了堆栈类,我想在其中存储 NSString 值。这是堆栈类:
@interface Stack : NSObject
- (void)push:(id)obj;
- (id)pop;
- (BOOL)isEmpty;
@end
@implementation Stack
{
NSMutableArray *stack;
}
- (id)init
{
self = [super init];
if(self!= nil){
stack = [[NSMutableArray alloc] init];
}
return self;
}
- (void)push:(id)obj
{
[stack addObject:obj];
}
- (id)pop
{
id lastobj = [stack lastObject];
[stack removeLastObject];
return lastobj;
}
- (BOOL)isEmpty
{
return stack.count == 0;
}
@end
我还有另一个名称为:TableViewController 我想何时单击 TableViewController 存储单元格中从 URL 接收的 id 中的单元格
这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// I want that xCode value with xCode2 value push in stack
NSLog(@"Row in Tab : %d",indexPath.row);
if ([Folder containsObject:[All objectAtIndex:indexPath.row]]) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.%d/mamal/filemanager.php?dir=%@&folder=%d&id",IP,xCode,indexPath.row]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *err = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *responseString = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];
xCode2 = responseString; //this is new cell's id.I want to push this value in stack
NSLog(@"xcode : %@", xCode2);
[self performSegueWithIdentifier:@"segue4" sender:self];
}
else
{
[self performSegueWithIdentifier:@"segue3" sender:self];
}
}
在顶部代码中,我想何时单击单元格推送堆栈中的两个值(xCode 和 xCode2),但我不知道要使用堆栈。