更新:在我实现 Players 之前,我的游戏数据库中有没有玩家的幽灵条目。它返回的是那些条目而不是更新后的模型的最新条目
我正在努力让 Core Data 数据库正常工作,但在关系上遇到了一些麻烦。我对整个事情很陌生,所以不要把任何东西放在我身边,我什至可能不了解基础知识。但无论如何我们都要去。
这是我创建一个新游戏实体的地方。Players 是与已选择并存储在数组中的多个 Player 实体的 to-may 关系。
Game *newGame = [NSEntityDescription insertNewObjectForEntityForName:@"Game" inManagedObjectContext:[SDDataManager dataManager].managedObjectContext];
[newGame setGameType:@"multipleChoice"];
[newGame setDate:[NSDate date]];
NSSet *playersSet = [NSSet setWithArray:players];
[newGame setPlayers:playersSet];
[newGame setCards:[NSKeyedArchiver archivedDataWithRootObject:selectedCards]];
NSError *error;
[[SDDataManager dataManager].managedObjectContext save:&error];
NSLog(@"New Game Error: %@",[error localizedDescription]);
Run Code Online (Sandbox Code Playgroud)
问题是,当我像这样从数据库中调用它时:
NSFetchRequest *requestSavedGame = [NSFetchRequest fetchRequestWithEntityName:@"Game"]; [requestSavedGame setFetchLimit:1];
NSError *error;
NSArray *loadedGame = [[SDDataManager dataManager].managedObjectContext executeFetchRequest:requestSavedGame error:&error];
NSLog(@"Load Game Error: %@",[error localizedDescription]);
Game *game = [loadedGame objectAtIndex:0];
NSLog(@"Players Set: %@",game.players);
NSLog(@"Players: %@",[game.players allObjects]);
Run Code Online (Sandbox Code Playgroud)
玩家:是空的??它准确地返回:
Players …Run Code Online (Sandbox Code Playgroud) 选择标签栏项时,我需要一直向上滚动表格视图.我试过这个,但它不起作用.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let tabBarIndex = tabBarController.selectedIndex
if tabBarIndex == 0 {
let indexPath = NSIndexPath(row: 0, section: 0)
MyViewController().tableView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
调用该方法但tableView不会滚动到顶部.
我正在学习Swift并学习一些教程.我一直收到错误:输入
'ViewController'不符合协议'UITableViewDataSource'
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var GetAllDataTest = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
GetAllDataTest = FMDBDatabaseModel.getInstance().GetAllData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell") as! TestTableViewCell
//cell.editData = self
cell.tag = indexPath.row
var l = Tbl_Test()
l = GetAllDataTest.object(at: indexPath.row) as! Tbl_Test
cell.lblName.text! = l.Name
cell.lblMobileNo.text! …Run Code Online (Sandbox Code Playgroud) 我需要在tableview标题中设置标题名称.我在代码中使用它
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section function
{
IView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
UILabel *lbl_header = [[UILabel alloc]initWithFrame:CGRectMake(12, 0, tableView.bounds.size.width, 30)];
lbl_header.tag=1000001;
lbl_header.backgroundColor = [UIColor clearColor];
lbl_header.textColor = [UIColor colorWithRed:204.0/255 green:204.0/255 blue:204.0/255 alpha:1.0];
lbl_header.font = [UIFont fontWithName:@"Helvetica-Regular" size:20];
//// get the title name from subclass view controller
HOAViewController *obj_hoaview_controll = [[HOAViewController alloc]init];
[obj_hoaview_controll fun_get_login_email_id];
lbl_header.text = str_email_id1;//[udf_value objectForKey:@"StrEmailGet"];
if (section == 0)
{
[headerView setBackgroundColor:[UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0]];
//lbl_header.text = [udf_value objectForKey:@"StrEmailGet"];
}
else …Run Code Online (Sandbox Code Playgroud) 我有一个视图,我想在其超级视图中水平和垂直居中。
我试过这个,但它不起作用:
let horConstraint = NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1.0, constant: 0.0)
view.addConstraints([horConstraint])
Run Code Online (Sandbox Code Playgroud) 如何在滚动不堆积时在tableViewCell中创建数据?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *theCell = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:theCell];
if (! cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:theCell];
}
UILabel *data1 = [self createLabelText:[NSString stringWithFormat:@"%@",[[arrayUtama objectAtIndex:indexPath.row]objectForKey:@"nomer"]]WithFrame:CGRectMake(10, 10, 150, 50) WithFont:[UIFont fontWithName:@"Arial" size:16] WithColor:[UIColor clearColor]];
[cell insertSubview:data1 atIndex:0];
UILabel *data2 = [self createLabelText:[NSString stringWithFormat:@"%@",[[arrayUtama objectAtIndex:indexPath.row]objectForKey:@"subjek"]]WithFrame:CGRectMake(50, 10, 150, 50) WithFont:[UIFont fontWithName:@"Arial" size:16] WithColor:[UIColor clearColor]];
[cell insertSubview:data2 atIndex:1];
UILabel *data3 = [self createLabelText:[NSString stringWithFormat:@"%@",[[arrayUtama objectAtIndex:indexPath.row]objectForKey:@"shadowScore"]]WithFrame:CGRectMake(200, 10, 150, 50) WithFont:[UIFont fontWithName:@"Arial" size:16] WithColor:[UIColor clearColor]];
[cell insertSubview:data3 …Run Code Online (Sandbox Code Playgroud) 我之前有一个类似的问题,但是添加分数却从未解决过,所以我想我现在就问它并同时修复这两个问题.我做了一个商店,人们可以在那里购买硬币,这些硬币将被添加到他们已有的硬币中.他们已经拥有的硬币可以通过以下方式加载:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadcoins = [defaults objectForKey:@"savedcoins"];
[coinsdisplay setText:loadstring];
Run Code Online (Sandbox Code Playgroud)
我有一个按钮,你可以买100个硬币
-(IBAction)savecoins100:(id)sender {
NSString *savecoins = @"100";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savecoins forKey:@"savedcoins"];
[defaults synchronize];
}
Run Code Online (Sandbox Code Playgroud)
我想要的是新的字符串不是@"100"而是100 +以前的硬币现在这将是loadcoins但我不知道如何正确编码这可以有人帮助我吗?
谢谢
ios ×7
objective-c ×3
swift ×3
uitableview ×3
autolayout ×1
cocoa-touch ×1
constraints ×1
core-data ×1
ipad ×1
iphone ×1
layout ×1
tableview ×1
xcode ×1