我有一个UITableView使用核心数据填充的NSFetchedResultsController.我现在已经UISegmentedControl在视图中添加了一个,当您更改当前段时,我希望更改tableview的内容.
我在网上读到,使用两种不同的NSFetchedResultsControllers方法是明智的,因为我可以从内置缓存中受益.唯一的问题是我似乎无法找到任何示例代码来执行此操作并且不知道从哪里开始.
任何人都可以解释从何处开始创建第二个NSFetchedResultsController并根据分段控件更改哪些来源的tableview?
查看标题代码:
#import <CoreData/CoreData.h>
@interface DomainViewController : UIViewController <NSFetchedResultsControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
UITableView *domainView;
UISegmentedControl *segmentedControl;
NSString *domain;
}
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSString *domain;
@property (nonatomic, retain) IBOutlet UITableView *domainView;
@property (nonatomic, retain) IBOutlet UISegmentedControl *segmentedControl;
- (IBAction)segmentedControlIndexChanged;
Run Code Online (Sandbox Code Playgroud)
查看实施代码:
@interface DomainViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation DomainViewController
@synthesize fetchedResultsController = __fetchedResultsController;
@synthesize managedObjectContext = __managedObjectContext; …Run Code Online (Sandbox Code Playgroud) 我有一个UITabBarController包含一个UINavigationController.在可见范围内UIViewController,我正在以UITableView编程方式创建如下:
self.voucherTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
self.voucherTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
Run Code Online (Sandbox Code Playgroud)
但是,UITabBar重叠了UITableView.
当我输出高度时[[UIScreen mainScreen] applicationFrame],它返回460.00,而它应该是367.00.
在Interface Builder中,我使用的是"模拟指标",它自动将视图的高度设置为367.00.
有什么我想念的东西,无论我尝试什么,我都看不到我需要的367.00高度.
作为一个临时修复,我已经设置了UITableView手动框架,这不是很理想,所以很好找出为什么这不起作用:
self.voucherTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 367) style:UITableViewStylePlain];
Run Code Online (Sandbox Code Playgroud) objective-c uitabbarcontroller uitableview uinavigationcontroller ios
我正在构建一个应用程序,根据您当前的位置显示结果数据.
目前,我正在使用a的viewDidLoad方法UIViewController来启动CLLocationManager并获取当前位置.一旦我的位置与我想要的准确度相匹配,我就会向我的Web服务请求获取结果并将其转储到UITableView.
我的问题是当你关闭应用程序时(虽然它仍然在后台运行).如果您要开车到另一个城镇,重新打开应用程序,数据将不会更新,并继续显示旧位置的结果.
基本上当UIViewController从后台加载时,我需要能够检查用户位置,如果他们已经移动了很长的距离,则更新我的内容UITableView.
但是,因为viewDidAppear的UIViewController当您加载从后台应用程序没有被触发,我不知道我能使用的方法.
我知道在stopMonitoringSignificantLocationChanges找到新位置时唤醒应用的方法.但是,这似乎有点OTT,因为我只需要知道应用程序加载后.
有没有替代stopMonitoringSignificantLocationChanges方法使用该方法?
我正在构建一个ASP.NET MVC 4应用程序,并希望将我的站点管理区域作为单独项目中的MVC区域.
我在我的解决方案中添加了一个新的MVC 4 Web应用程序项目,并添加了以下文件来注册我的区域:
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "Admin"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", area = "Admin", id = UrlParameter.Optional },
new[] { "Future.Admin.Controllers" }
);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这会导致以下错误:
A route named 'Admin_default' is already in the route collection. Route names must be unique.
Run Code Online (Sandbox Code Playgroud)
我已将管理区项目的构建输出路径更改为指向主站点项目.
有什么我缺少或没有配置?
任何帮助深表感谢!
我正试图将一个Base64String回归到一个Image.我在我的C#控制台应用程序中设置了此代码.
public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}
Run Code Online (Sandbox Code Playgroud)
我每次使用该类型时都会收到错误Image.它说:
找不到类型或命名空间名称.
我正在使用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Net.Mime;
using System.Drawing;
Run Code Online (Sandbox Code Playgroud)
我错过了一个图书馆吗?
使用@Html.TextBoxFor我创建的自定义类型渲染文本框时遇到问题.我的自定义类型如下所示:
public class Encrypted<T>
{
private readonly Lazy<T> _decrypted;
private readonly Lazy<string> _encrypted;
public static implicit operator Encrypted<T>(T value)
{
return new Encrypted<T>(value);
}
public static implicit operator string(Encrypted<T> value)
{
return value._encrypted.Value;
}
...
}
Run Code Online (Sandbox Code Playgroud)
然后在我的模型上,我有:
public class ExampleModel
{
public Encrypted<string> Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我手动填充控制器操作中的值:
public ActionResult Index()
{
var model = new ExampleModel
{
Name = "Example Name";
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
然后我认为我有标准@Html.TextBoxFor(m => m.Name).但是,当渲染时,我的文本框的值设置为:Services.Encrypted`1 [System.String]`
大概这是因为我使用的是自定义类型,编译器不知道如何将我的类型转换为字符串值.
我尝试过使用自定义TypeConverter: …
我正在尝试构建一个iPhone应用程序和c#WCF服务,以将图像上传到SQL服务数据库.
我的应用程序将图像分解为NSData并使用以下代码发布到WCF服务:
NSData *imageData = UIImageJPEGRepresentation(self.image, 90);
NSURL *url = [NSURL URLWithString:@"http://example.com/ImageDiaryService.svc/json/AddMediaItem"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Test" forKey:@"Name"];
[request setPostValue:@"Test description." forKey:@"Description"];
[request setPostValue:@"JPEG" forKey:@"ImageType"];
[request setPostValue:@"iPhone" forKey:@"MediaType"];
[request setData:imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"ImageData"];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDelegate:self];
[request startAsynchronous];
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是Web服务.我不确定应该从app POST接收什么类型的数据.我试过把它作为一个字节数组接收但是没有用.
我的WCF服务是一项REST服务.
任何帮助深表感谢.
我有一些页面内容,其中包含以下代码行的多次出现:
<li class="r"><h3><a href="/test-url.htm">test string</a></h3></li>
Run Code Online (Sandbox Code Playgroud)
我正在使用.NET Regex查找内容中的所有匹配项并返回锚标记的href.
我的问题是,有时候<li>引号缠绕在类中(如上所示),但其他人没有,只是有:class=r
我需要有和没有引号的比赛.
我尝试了各种方法,但似乎没有任何工作.当有报价时,它们都匹配,但不是没有报价.以下是我目前的尝试:
Regex _Regex = new Regex(@"<li class=(?:"")g([^>])*>((?!<h3).)*<h3([^>])*><a\shref=""(?<URL>[^""]*)""([^>])*>((?!</li).)*", RegexOptions.IgnoreCase);
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢,
谢谢.
我有一些List产品,我需要从列表中获取具有Id我从查询字符串参数获得的特定产品的项目.但是,我可能并不总是将产品Id传递给我.如果我没有产品Id,我需要默认使用列表中的第一个产品.
目前我有:
@Model.Products.FirstOrDefault(x => x.Id == productId);
Run Code Online (Sandbox Code Playgroud)
这只是选择具有该特定的产品Id,如果没有,则默认为null.
有没有办法实现我想要的?
我正在尝试弄清楚我的webforms Page是否是某种类型.
我有许多基类互相继承:
BasePage -> System.Web.UI.Page
CMSPage -> BasePage
Page -> CMSPage
Run Code Online (Sandbox Code Playgroud)
在自定义中UserControl,我需要获取页面,但前提是它来自CMSPage.
我试过了:
if(Page.GetType() == typeof(CMSPage))
Run Code Online (Sandbox Code Playgroud)
但GetType()的值只返回页面的类名.看起来我需要这样做:
if(Page.GetType().BaseType.BaseType == typeof(CMSPage))
Run Code Online (Sandbox Code Playgroud)
让比赛奏效.但是,有些页面在BaseType达到类型之前处于不同的级别CMSPage.
我可以创建一个这样的函数来遍历每个函数,BaseType直到找到正确的函数:
public static bool IsPageTypeOf(this System.Web.UI.Page page, Type targetType)
{
var pageType = page.GetType();
if (pageType == targetType)
return true;
while (pageType.BaseType != null)
{
if (pageType.BaseType == targetType)
return true;
pageType = pageType.BaseType;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
但它感觉很乱.有一个更好的方法吗?
c# ×7
asp.net-mvc ×3
ios ×3
objective-c ×3
asp.net ×2
iphone ×2
.net ×1
base64 ×1
core-data ×1
geolocation ×1
image ×1
linq ×1
razor ×1
regex ×1
tableview ×1
types ×1
uitableview ×1
wcf ×1