- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在理解如何保存数据以便为我的应用程序提供“添加到收藏夹”功能时遇到了这个问题。该应用程序有一个 UITableView,数据存储在 Plist 中。从那里它进入包含 UIImageView 和 UITextView 的 DetailView。我希望能够为我喜欢的项目添加书签并将它们显示在单独的 View 。
下面是一段代码,以便于查看:
//BooksLibraryDao.h
#import <Foundation/Foundation.h>
@interface BooksLibraryDao : NSObject {
NSString *libraryPlist;
NSArray *libraryContent;
}
@property (nonatomic, readonly) NSString *libraryPlist;
@property (nonatomic, readonly) NSArray *libraryContent;
- (id)initWithLibraryName:(NSString *)libraryName;
- (NSDictionary *)libraryItemAtIndex:(int)index;
- (int)libraryCount;
@end
//BooksLibraryDao.m
#import "BooksLibraryDao.h"
@implementation BooksLibraryDao
@synthesize libraryContent, libraryPlist;
- (id)initWithLibraryName:(NSString *)libraryName {
if (self = [super init]) {
libraryPlist = libraryName;
libraryContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:libraryPlist ofType:@"plist"]];
}
return self;
}
- (NSDictionary *)libraryItemAtIndex:(int)index {
return (libraryContent != nil && [libraryContent count] > 0 && index < [libraryContent count])
? [libraryContent objectAtIndex:index]
: nil;
}
- (int)libraryCount {
return (libraryContent != nil) ? [libraryContent count] : 0;
}
- (void) dealloc {
if (libraryContent) [libraryContent release];
[super dealloc];
}
@end
//BooksTableViewController.h
#import <UIKit/UIKit.h>
#import "BooksLibraryDao.h"
#import "BooksListingViewCell.h"
#import "BooksAppDelegate.h"
@interface BooksTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *booksTableView;
BooksLibraryDao *dao;
IBOutlet BooksListingViewCell *_cell;
}
@end
//BooksTableViewController.m
#import "BooksTableViewController.h"
#import "DetailViewController.h"
#import "BooksListingViewCell.h"
#import "BooksNavController.h"
@implementation BooksTableViewController
#define CELL_HEIGHT 70.0
#pragma mark -
#pragma mark Initialization
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
self = [super initWithStyle:style];
if (self) {
// Custom initialization.
}
return self;
}
*/
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor clearColor];
}
- (void)viewWillAppear:(BOOL)animated {
dao = [[BooksLibraryDao alloc] initWithLibraryName:@"TestData"];
self.title = @"Books";
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [dao libraryCount];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"LibraryListingCell";
BooksListingViewCell *cell = (BooksListingViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"BooksListingView" owner:self options:nil];
cell = [_cell autorelease];
_cell = nil;
}
cell.titleLabel.text = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];
cell.smallImageView.image = [UIImage imageNamed:[[dao libraryItemAtIndex:indexPath.row] valueForKey:@"smallImage"]];
cell.backgroundColor = [UIColor colorWithRed:9 green:9 blue:9 alpha:.7];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:1];
cell.selectedBackgroundView = [[[UIImageView alloc] init] autorelease];
UIImage *selectionBackground;
selectionBackground = [UIImage imageNamed:@"cell.png"];
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *controller = [[DetailViewController alloc]
initWithBookData:[dao libraryItemAtIndex:indexPath.row]
nibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
controller.title = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return CELL_HEIGHT;
}
#pragma mark -
#pragma mark Table view delegate
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
//DetailViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <QuartzCore/QuartzCore.h>
@interface DetailViewController : UIViewController <MFMailComposeViewControllerDelegate>{
IBOutlet UIImageView *bookImageView;
IBOutlet UILabel *titleLabel;
IBOutlet UITextView *authorTextView;
IBOutlet UITextView *descriptionTextView;
IBOutlet UILabel *message;
NSDictionary *bookData;
}
@property (nonatomic, retain) UIImageView *bookImageView;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UITextView *descriptionTextView;
@property (nonatomic, retain) UITextView *authorTextView;
@property (nonatomic, retain) IBOutlet UILabel *message;
-(IBAction)showPicker:(id)sender;
-(void)displayComposerSheet;
-(void)launchMailAppOnDevice;
-(IBAction)showAuthor;
-(IBAction)showDesc;
-(IBAction)showImage;
- (id)initWithBookData:(NSDictionary *)data nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
@end
//DetailViewController.m
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize bookImageView, titleLabel, descriptionTextView, authorTextView;
@synthesize message;
- (id)initWithBookData:(NSDictionary *)data nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
bookData = data;
}
return self;
}
- (void)viewDidLoad {
bookImageView.image = [UIImage imageNamed:[bookData valueForKey:@"bookImage"]];
titleLabel.text = [bookData valueForKey:@"title"];
descriptionTextView.text = [bookData valueForKey:@"description"];
authorTextView.text = [bookData valueForKey:@"author"];
[super viewDidLoad];
}
最佳答案
您可以选择实现收藏夹的几个选项之一(实际上主要取决于您的数据是否持久)。
(A) 您可以为表格中显示的每个项目添加标记,这将其标记为最喜欢的 - 然后只需引用相同的数据集但过滤它的标记。或者...
(B) 您可以创建一个附加列表,其中包含每个项目的副本您想要标记为收藏夹,然后将该新列表引用为您的数据源。
如果您的数据不是持久性的,您仍然可以使用方法 A,并且在刷新数据时仅保留标记的记录,然后再插入新的新鲜数据。
希望这是有道理的!
关于iphone - 添加到收藏夹功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598794/
UICollectionView单元格我在单个按钮中显示具有喜欢和不喜欢选项的产品,它位于collectionview cell中。每当我滚动UICollectionview单元格“收藏夹”时,它就会
我正在使用 Tridion 2011。我正在寻找一种方法让用户重命名收藏的链接。将组件、文件夹等添加到收藏夹很简单,但有没有办法让用户重命名这些收藏夹链接? 最佳答案 开箱即用,无法以不同于原始项目的
您好,我是一名自学 Flutter 的开发人员,正在编写我的第一个应用程序。我正在 Flutter 中构建一个基本的报价应用程序,它使用 Firebase 进行身份验证,使用 FireStore 作为
如何自动完成在“邮件收藏夹”文件夹中显示公用文件夹日历的过程? 我想通过登录脚本或通过组策略来做到这一点。 我将Microsoft Exchange Server 2007与Windows Serve
我无法让它工作...可能是什么问题? import flickrapi api_key = '1234...' flickr = flickrapi.FlickrAPI(api_key) user =
代码如下: using System; using System.Data; using System.Configuration; using System
我正在考虑将 CouchDB 用于即将推出的网站,但就如何为该网站实现用户评分系统而言,我有点困惑。基本上,每个内容项都可以由给定用户评分。哪种方式在 CouchDB 模型中最有意义?我认为最干燥和最
是否可以为 Internet Explorer 开发一个插件来替代现有的收藏夹功能? 最佳答案 当然,这确实在某种程度上取决于您期望“替换”的含义。您可以开发一个扩展来提供一组新的菜单或某种类型的下拉
我正在尝试在网站上实现收藏夹系统,例如在 stackoverflow.com 上:如果您单击星号图标,则会交换图像以显示它现在是最喜欢的。只是就我而言,被收藏的不是问题而是用户。到目前为止还没有什么大
我是 react-redux 世界的新手,在可视化一段复杂的数据流时遇到了一些困难(我认为)。 假设状态包含一组轨道和一组最喜欢的轨道 ID。用户可以从许多不同的组件中收藏一首轨道,例如音乐播放器、轨
当我单击它并单击列表中的所有项目时,我在列表 View 中有“收藏夹”按钮,我如何使用共享首选项修复此问题,这是我的代码: 在我的stfl状态下: static const likedKey =
我是 iOS 新手。我想在我的应用程序的顶部菜单上放置一个“星标”按钮。有没有办法让 iOS 中内置的星形按钮类似于 UIBarButtonSystemItemAdd 如果没有,我怎样才能得到类似于
到目前为止,我已经尝试使用简单的 php GET 请求和 POST 请求,但似乎没有任何效果。 这是我迄今为止的 Javascript 代码: $(document).ready(function()
这是我的表“用户”的样子: Name Password Favorites Test Test 1 2 3 4 在我的表“数据”中有 Comment ID "Test" 2 我希望用户能够将
我正在开发一个应用程序,我有一个要求。我必须处理自定义单元格上的收藏夹按钮。我正在创建带有单元格图像的自定义按钮,并设置未选择的类型我默认提供的收藏图像,一旦用户单击单元格上的收藏按钮,我正在更改按钮
我还是个初学者,才刚刚开始学扑翼。我关注的是谷歌Codelabs上的“你的第一款颤动应用”,并止步于这一步:https://codelabs.developers.google.com/codelab
我还是个初学者,才刚刚开始学扑翼。我关注的是谷歌Codelabs上的“你的第一款颤动应用”,并止步于这一步:https://codelabs.developers.google.com/codelab
因此,根据我的搜索,这是 iOS/Apple 端长期存在的错误。到目前为止,我还无法确认解决方法,所以想看看我是否能加快速度。 我在 realfavicongenerator 的帮助下在我的网站上合并
你好亲爱的stackoverflow friend 几个月前我问过你一个关于 QuickAccess (Pin/Unpin) 的问题.不幸的是,我们仍然面临这个问题(无法取消固定虚拟对象)。在多次调用
我是一名优秀的程序员,十分优秀!