gpt4 book ai didi

ios objective c todo 应用程序

转载 作者:行者123 更新时间:2023-11-28 21:40:41 24 4
gpt4 key购买 nike

总体而言,我对 Objective C、Xcode 和 iOS 开发还很陌生。我只是想创建一个简单的 TODO 应用程序,但我没有完成检查。每次我单击一个项目时,我都会在控制台日志中得到一个 (lldb) 和一个线程 1:断点 1.1,我不知道它指的是什么。我的断点出现在最后一行 [tableView deselectRowAtIndexPath:indexPath animated:YES]; 我不确定这里发生了什么。任何帮助将不胜感激。

#import "TDOViewController.h"

@interface TDOViewController () <UIAlertViewDelegate>

@property (nonatomic) NSMutableArray *items;

@end

@implementation TDOViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// Handles list of items
self.items = @[@{@"name" : @"Take out the trash", @"category" : @"home"}, @{@"name" : @"Shoes", @"category" : @"home"}].mutableCopy;

// Handles navigation bar
self.navigationItem.title = @"To-Do List";

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem:)];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Adding Items
- (void)addNewItem:(UIBarButtonItem *) sender {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New ToDo Item" message:@"Enter name of new ToDo Item" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add Item", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != alertView.cancelButtonIndex) {
UITextField * itemNameField = [alertView textFieldAtIndex:0];
NSString *itemName = itemNameField.text;
NSDictionary *item = @{@"name" : itemName, @"category" : @"home"};
[self.items addObject:item];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.items.count - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}

#pragma mark - Table view datasource

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TodoItemRow";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

NSDictionary *item = self.items[indexPath.row];

cell.textLabel.text = item[@"name"];

if ([item[@"completed"] boolValue]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *item = [self.items[indexPath.row] mutableCopy];
BOOL completed = [item[@"completed"] boolValue];
item[@"completed"] = @(!completed);

self.items[indexPath.row] = item;

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = ([item[@"completed"] boolValue]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end

最佳答案

单击边距中的行号将设置一个断点,该断点会在运行时停止执行该行代码的任何时间。

这对于查找代码中的错误很有用,但如果您不小心放置了它们,就会有点烦人。只需单击蓝色箭头即可禁用断点,单击并将其拖离边缘即可将其删除。

您还可以通过在控制台工具栏中禁用它们来全局关闭断点。

关于ios objective c todo 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32193048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com