gpt4 book ai didi

swift - 我正在制作简单的Note应用程序。但是,当我运行该应用程序时,它无法处理此错误消息线程1:在AppDelegate类中发出SIGABRT信号

转载 作者:行者123 更新时间:2023-11-30 11:50:13 25 4
gpt4 key购买 nike

我正在制作简单的应用程序。

我在简单的应用程序上做了一些单元格和按钮。

但是我遇到了这个错误信息:


  libc ++ abi.dylib:以类型未捕获的异常终止
  NSException


有些收到该错误消息的人已经问过。

我已经读过他们的问题...但是没有人遇到相同的问题。

而且AppDelegate类中存在该问题

我将向您展示我的代码。

lazy var list: [NSManagedObject] = {
return self.fetch()
}()

//데이터를 읽어올 메소드
func fetch() -> [NSManagedObject] {
//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 요청 객체 생성
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Board")
//3-1 정렬 속성 설정
let sort = NSSortDescriptor(key: "regdate", ascending: false)
fetchRequest.sortDescriptors = [sort]
//4 데이터 가져오기
let result = try! context.fetch(fetchRequest)
return result

}

//데이터를 저장할 메소드
func save(title: String, contents: String) -> Bool {
//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 관리 객체 생성 & 값을 설정
let object = NSEntityDescription.insertNewObject(forEntityName: "Board", into: context)

object.setValue(title, forKey: "title")
object.setValue(contents, forKey: "contents")
object.setValue(Date(), forKey: "regdate")

//4 영구 저장소에 커밋되고 나면 list 프로퍼팅 추가한다.
do {
try context.save()
//self.list.append(object)
self.list.insert(object, at: 0)
return true
} catch {
context.rollback()
return false
}
}

//화면 및 로직 초기화 메소드
override func viewDidLoad() {
let addBtn = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(add(_:)))
self.navigationItem.rightBarButtonItem = addBtn
}

//데이터 저장 버튼에 대한 액션 메소드
@objc func add(_ sender: Any) {
let alert = UIAlertController(title: "게시글 등록", message: nil, preferredStyle: .alert)

//입력 필드 추가(이름 & 전화번호)
alert.addTextField() {$0.placeholder = "제목"}
alert.addTextField() {$0.placeholder = "내용"}

//버튼 추가 (cancel & save)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alert.addAction(UIAlertAction(title: "Save", style: .default) {(_) in
guard let title = alert.textFields?.first?.text, let contents = alert.textFields?.last?.text else {
return
}
//값을 저장하고 성공이면 테이블 뷰를 리로드한다.
if self.save(title: title, contents: contents) == true {
self.tableView.reloadData()
}
})
self.present(alert, animated: false)
}

func delete(object: NSManagedObject) -> Bool {

//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 컨텍스트로부터 해당 객체 삭제
context.delete(object)
//4 영구저장소에 커밋한다.
do {
try context.save()
return true
} catch {
context.rollback()
return false
}
}

//데이터 수정 처리를 담당할 edit메소드 구현
func edit(object: NSManagedObject, title: String, contents: String) -> Bool {

//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 관리 객체의 값을 수정
object.setValue(title, forKey: "title")
object.setValue(contents, forKey: "contents")
object.setValue(Date(), forKey: "regdate")

//영구 저장소에 반영한다.
do {
try context.save()
self.list = self.fetch()
return true
} catch {
context.rollback()
return false
}
}


这是我的完整错误信息
2018-01-23 21:38:58.066127 + 0900 Chapter07-CoreData [2427:173395] *-[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:],/ BuildRoot / Library / Caches / com.apple.xbs / Sources /中的断言失败UIKit_Sim / UIKit-3694.4.18 / UITableView.m:7732
2018-01-23 21:38:58.072324 + 0900 Chapter07-CoreData [2427:173395] *由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使标识符为Cell的单元出队-必须注册一个笔尖或一个类标识符或在情节提要中连接原型单元”
***首先抛出调用堆栈:

    0 CoreFoundation 0x0000000113eec1cb异常预处理+ 171
    1 libobjc.A.dylib 0x000000010ffccf41 objc_exception_throw + 48
    2 CoreFoundation 0x0000000113ef1362 + [NSException提高:格式:参数:] + 98
    3 Foundation 0x000000010fa71089-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4 UIKit 0x0000000110c20968-[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] + 890
    5 UIKit 0x0000000110c205ba-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 89
    6 Chapter07-CoreData 0x000000010f6a80ab _T018Chapter07_CoreData6ListVCC9tableViewSo07UITableG4CellCSo0hG0C_10Foundation9IndexPathV12cellForRowAttF + 2123
    7 Chapter07-CoreData 0x000000010f6a866c _T018Chapter07_CoreData6ListVCC9tableViewSo07UITableG4CellCSo0hG0C_10Foundation9IndexPathV12cellForRowAttFTo + 92
    8 UIKit 0x0000000110c3bef0-[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 727
    9 UIKit 0x0000000110c3c4ab-[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    10 UIKit 0x0000000110c02870-[UITableView _updateVisibleCellsNow:isRecursive:] + 2892
    11 UIKit 0x0000000110c23de9-[UITableView layoutSubviews] + 176
    12 UIKit 0x0000000110bb1551-[UIView(CALayerDelegate)layoutSublayersOfLayer:] + 1331
    13 QuartzCore 0x00000001174b04ba-[CALayer layoutSublayers] + 153
    14 QuartzCore 0x00000001174b45a9 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
    15 QuartzCore 0x000000011743d1cd _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365
    16 QuartzCore 0x0000000117468ae4 _ZN2CA11Transaction6commitEv + 500
    17 UIKit 0x0000000110afe706 __34- [UIApplication _firstCommitBlock] _block_invoke_2 + 141
    18 CoreFoundation 0x0000000113e8f20c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
    19 CoreFoundation 0x0000000113e73a3b __CFRunLoopDoBlocks + 203
    20 CoreFoundation 0x0000000113e73214 __CFRunLoopRun + 1300
    21 CoreFoundation 0x0000000113e72a89 CFRunLoopRunSpecific + 409
    22图形服务0x00000001166649c6 GSEventRunModal + 62
    23 UIKit 0x0000000110ae2d30 UIApplicationMain + 159
    24第07章-CoreData 0x000000010f6b06a7 main + 55
    25 libdyld.dylib 0x0000000115015d81开始+ 1

libc ++ abi.dylib:以NSException类型的未捕获异常终止
(lldb)

最佳答案

似乎您正在使用tableView在应用程序中的某些位置,并且情节提要中的单元格标识符未设置为“ Cell”。确保您的故事板身份检查器中的单元格标识符设置为与代码中的标识符匹配

关于swift - 我正在制作简单的Note应用程序。但是,当我运行该应用程序时,它无法处理此错误消息线程1:在AppDelegate类中发出SIGABRT信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48401090/

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